Submission #902648
Source Code Expand
// package atcoder.other2016.codefestival2016.quala; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.List; public class Main { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); int q = in.nextInt(); int[] a = in.nextInts(q); for (int i = 0; i < q ; i++) { a[i]--; } int[] ord = makeord(m, a); out.println(isOK(n, m, a, ord) ? "Yes" : "No"); out.flush(); } private static int[] makeord(int m, int[] a) { boolean[] seen = new boolean[m]; int[] ord = new int[m]; int oi = 0; for (int i = a.length-1 ; i >= 0 ; i--) { if (!seen[a[i]]) { seen[a[i]] = true; ord[oi++] = a[i]; } } for (int i = 0; i < m ; i++) { if (!seen[i]) { ord[oi++] = i; } } return ord; } private static boolean isOK(int n, int m, int[] a, int[] ord) { int[] iord = new int[m]; Arrays.fill(iord, -1); for (int i = 0; i < ord.length; i++) { iord[ord[i]] = i; } int on = ord.length; int[] cnt = new int[on+1]; cnt[0] = n; for (int i = a.length-1; i >= 0; i--) { int th = iord[a[i]]; if (cnt[th] >= 1) { cnt[th]--; cnt[th+1]++; } } for (int i = 0; i <= on ; i++) { if (cnt[i] >= 1) { int[] ord2 = new int[m]; int oi = 0; boolean[] seen = new boolean[m]; for (int j = 0; j < i ; j++) { ord2[oi++] = ord[j]; seen[ord[j]] = true; } for (int j = 0; j < m ; j++) { if (!seen[j]) { ord2[oi++] = j; } } return Arrays.equals(ord, ord2); } } throw new RuntimeException("nyan"); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } private int[] nextInts(int n) { int[] ret = new int[n]; for (int i = 0; i < n; i++) { ret[i] = nextInt(); } return ret; } private int[][] nextIntTable(int n, int m) { int[][] ret = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ret[i][j] = nextInt(); } } return ret; } private long[] nextLongs(int n) { long[] ret = new long[n]; for (int i = 0; i < n; i++) { ret[i] = nextLong(); } return ret; } private long[][] nextLongTable(int n, int m) { long[][] ret = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ret[i][j] = nextLong(); } } return ret; } private double[] nextDoubles(int n) { double[] ret = new double[n]; for (int i = 0; i < n; i++) { ret[i] = nextDouble(); } return ret; } private int next() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public char nextChar() { int c = next(); while (isSpaceChar(c)) c = next(); if ('a' <= c && c <= 'z') { return (char) c; } if ('A' <= c && c <= 'Z') { return (char) c; } throw new InputMismatchException(); } public String nextToken() { int c = next(); while (isSpaceChar(c)) c = next(); StringBuilder res = new StringBuilder(); do { res.append((char) c); c = next(); } while (!isSpaceChar(c)); return res.toString(); } public int nextInt() { int c = next(); while (isSpaceChar(c)) c = next(); int sgn = 1; if (c == '-') { sgn = -1; c = next(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c-'0'; c = next(); } while (!isSpaceChar(c)); return res*sgn; } public long nextLong() { int c = next(); while (isSpaceChar(c)) c = next(); long sgn = 1; if (c == '-') { sgn = -1; c = next(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c-'0'; c = next(); } while (!isSpaceChar(c)); return res*sgn; } public double nextDouble() { return Double.valueOf(nextToken()); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static void debug(Object... o) { System.err.println(Arrays.deepToString(o)); } }
Submission Info
Submission Time | |
---|---|
Task | E - LRU Puzzle |
User | hamadu |
Language | Java8 (OpenJDK 1.8.0) |
Score | 1200 |
Code Size | 6776 Byte |
Status | AC |
Exec Time | 268 ms |
Memory | 11872 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1200 / 1200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt, 1_64.txt, 1_65.txt, 1_66.txt, 1_67.txt, 1_68.txt, 1_69.txt, 1_70.txt, 1_71.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 96 ms | 8016 KB |
0_01.txt | AC | 96 ms | 8016 KB |
0_02.txt | AC | 96 ms | 8020 KB |
0_03.txt | AC | 96 ms | 8016 KB |
1_00.txt | AC | 95 ms | 8272 KB |
1_01.txt | AC | 94 ms | 8148 KB |
1_02.txt | AC | 134 ms | 11088 KB |
1_03.txt | AC | 134 ms | 11088 KB |
1_04.txt | AC | 133 ms | 10964 KB |
1_05.txt | AC | 141 ms | 10836 KB |
1_06.txt | AC | 141 ms | 10960 KB |
1_07.txt | AC | 140 ms | 10960 KB |
1_08.txt | AC | 139 ms | 10960 KB |
1_09.txt | AC | 138 ms | 11092 KB |
1_10.txt | AC | 136 ms | 10320 KB |
1_11.txt | AC | 147 ms | 10448 KB |
1_12.txt | AC | 145 ms | 10448 KB |
1_13.txt | AC | 138 ms | 10320 KB |
1_14.txt | AC | 146 ms | 10064 KB |
1_15.txt | AC | 144 ms | 10324 KB |
1_16.txt | AC | 148 ms | 10068 KB |
1_17.txt | AC | 128 ms | 10068 KB |
1_18.txt | AC | 139 ms | 10704 KB |
1_19.txt | AC | 148 ms | 10192 KB |
1_20.txt | AC | 149 ms | 10964 KB |
1_21.txt | AC | 149 ms | 11216 KB |
1_22.txt | AC | 140 ms | 10964 KB |
1_23.txt | AC | 150 ms | 10704 KB |
1_24.txt | AC | 151 ms | 11872 KB |
1_25.txt | AC | 148 ms | 10448 KB |
1_26.txt | AC | 129 ms | 9300 KB |
1_27.txt | AC | 128 ms | 9296 KB |
1_28.txt | AC | 128 ms | 9296 KB |
1_29.txt | AC | 129 ms | 9300 KB |
1_30.txt | AC | 130 ms | 10448 KB |
1_31.txt | AC | 126 ms | 10576 KB |
1_32.txt | AC | 128 ms | 10196 KB |
1_33.txt | AC | 141 ms | 10832 KB |
1_34.txt | AC | 139 ms | 9848 KB |
1_35.txt | AC | 140 ms | 10068 KB |
1_36.txt | AC | 137 ms | 9808 KB |
1_37.txt | AC | 141 ms | 10588 KB |
1_38.txt | AC | 137 ms | 10576 KB |
1_39.txt | AC | 145 ms | 10708 KB |
1_40.txt | AC | 268 ms | 11348 KB |
1_41.txt | AC | 151 ms | 10960 KB |
1_42.txt | AC | 129 ms | 9296 KB |
1_43.txt | AC | 130 ms | 9424 KB |
1_44.txt | AC | 126 ms | 9296 KB |
1_45.txt | AC | 127 ms | 9300 KB |
1_46.txt | AC | 133 ms | 9552 KB |
1_47.txt | AC | 124 ms | 9808 KB |
1_48.txt | AC | 125 ms | 9808 KB |
1_49.txt | AC | 129 ms | 10704 KB |
1_50.txt | AC | 122 ms | 9296 KB |
1_51.txt | AC | 119 ms | 9428 KB |
1_52.txt | AC | 124 ms | 9296 KB |
1_53.txt | AC | 124 ms | 9296 KB |
1_54.txt | AC | 145 ms | 10704 KB |
1_55.txt | AC | 135 ms | 10068 KB |
1_56.txt | AC | 136 ms | 10960 KB |
1_57.txt | AC | 143 ms | 10828 KB |
1_58.txt | AC | 126 ms | 9168 KB |
1_59.txt | AC | 129 ms | 9424 KB |
1_60.txt | AC | 129 ms | 9296 KB |
1_61.txt | AC | 119 ms | 9296 KB |
1_62.txt | AC | 125 ms | 9940 KB |
1_63.txt | AC | 138 ms | 10836 KB |
1_64.txt | AC | 123 ms | 9808 KB |
1_65.txt | AC | 130 ms | 10580 KB |
1_66.txt | AC | 130 ms | 9300 KB |
1_67.txt | AC | 128 ms | 9172 KB |
1_68.txt | AC | 122 ms | 9296 KB |
1_69.txt | AC | 121 ms | 9296 KB |
1_70.txt | AC | 135 ms | 10960 KB |
1_71.txt | AC | 144 ms | 10576 KB |