Submission #900238
Source Code Expand
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Main { static InputStream is; static PrintWriter out; static String INPUT = ""; static void solve() { int n = ni(), m = ni(); int Q = ni(); int[] a = na(Q); for(int i = 0;i < Q;i++)a[i]--; boolean[] used = new boolean[m]; int[] last = new int[m]; int p = 0; for(int i = Q-1;i >= 0;i--){ if(!used[a[i]]){ used[a[i]] = true; last[p++] = a[i]; } } for(int i = 0;i < m;i++){ if(!used[i]){ last[p++] = i; } } int[] ilast = new int[m]; for(int i = 0;i < m;i++)ilast[last[i]] = i; int[] ps = new int[m]; for(int i = Q-1;i >= 0;i--){ int id = ilast[a[i]]; if(ps[id] < n && (id == 0 || ps[id-1] >= ps[id] + 1)){ ps[id]++; }else if(ps[id] < n && (id > 0 && ps[id-1] == 0)){ out.println("No"); return; } } int nat = m-1; for(int i = m-2;i >= 0;i--){ if(last[i] < last[i+1]){ nat--; }else{ break; } } for(int i = 0;i < nat;i++){ if(ps[i] != n){ out.println("No"); return; } } out.println("Yes"); } public static void main(String[] args) throws Exception { long S = System.currentTimeMillis(); is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); solve(); out.flush(); long G = System.currentTimeMillis(); tr(G-S+"ms"); } private static boolean eof() { if(lenbuf == -1)return true; int lptr = ptrbuf; while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false; try { is.mark(1000); while(true){ int b = is.read(); if(b == -1){ is.reset(); return true; }else if(!isSpaceChar(b)){ is.reset(); return false; } } } catch (IOException e) { return true; } } private static byte[] inbuf = new byte[1024]; static int lenbuf = 0, ptrbuf = 0; private static int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } // private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); } private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private static double nd() { return Double.parseDouble(ns()); } private static char nc() { return (char)skip(); } private static String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private static char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private static char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private static int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private static int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); } }
Submission Info
Submission Time | |
---|---|
Task | E - LRU Puzzle |
User | uwi |
Language | Java8 (OpenJDK 1.8.0) |
Score | 1200 |
Code Size | 4380 Byte |
Status | AC |
Exec Time | 138 ms |
Memory | 10832 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 | 97 ms | 8016 KB |
0_01.txt | AC | 96 ms | 8020 KB |
0_02.txt | AC | 97 ms | 8016 KB |
0_03.txt | AC | 95 ms | 8148 KB |
1_00.txt | AC | 97 ms | 8020 KB |
1_01.txt | AC | 94 ms | 8148 KB |
1_02.txt | AC | 129 ms | 10704 KB |
1_03.txt | AC | 128 ms | 10452 KB |
1_04.txt | AC | 131 ms | 10832 KB |
1_05.txt | AC | 134 ms | 10576 KB |
1_06.txt | AC | 121 ms | 10452 KB |
1_07.txt | AC | 119 ms | 10580 KB |
1_08.txt | AC | 125 ms | 10448 KB |
1_09.txt | AC | 123 ms | 10580 KB |
1_10.txt | AC | 135 ms | 9936 KB |
1_11.txt | AC | 124 ms | 9940 KB |
1_12.txt | AC | 129 ms | 9940 KB |
1_13.txt | AC | 122 ms | 9936 KB |
1_14.txt | AC | 132 ms | 10068 KB |
1_15.txt | AC | 131 ms | 9940 KB |
1_16.txt | AC | 123 ms | 9936 KB |
1_17.txt | AC | 131 ms | 9808 KB |
1_18.txt | AC | 120 ms | 10448 KB |
1_19.txt | AC | 121 ms | 9940 KB |
1_20.txt | AC | 121 ms | 10448 KB |
1_21.txt | AC | 120 ms | 10580 KB |
1_22.txt | AC | 119 ms | 10452 KB |
1_23.txt | AC | 123 ms | 10196 KB |
1_24.txt | AC | 122 ms | 10452 KB |
1_25.txt | AC | 122 ms | 10068 KB |
1_26.txt | AC | 118 ms | 9168 KB |
1_27.txt | AC | 119 ms | 9172 KB |
1_28.txt | AC | 122 ms | 9172 KB |
1_29.txt | AC | 125 ms | 9168 KB |
1_30.txt | AC | 138 ms | 10192 KB |
1_31.txt | AC | 136 ms | 10324 KB |
1_32.txt | AC | 126 ms | 9936 KB |
1_33.txt | AC | 137 ms | 10320 KB |
1_34.txt | AC | 121 ms | 9552 KB |
1_35.txt | AC | 128 ms | 9808 KB |
1_36.txt | AC | 121 ms | 9552 KB |
1_37.txt | AC | 133 ms | 9812 KB |
1_38.txt | AC | 136 ms | 10192 KB |
1_39.txt | AC | 132 ms | 10380 KB |
1_40.txt | AC | 121 ms | 10448 KB |
1_41.txt | AC | 127 ms | 10576 KB |
1_42.txt | AC | 127 ms | 9296 KB |
1_43.txt | AC | 118 ms | 9296 KB |
1_44.txt | AC | 117 ms | 9296 KB |
1_45.txt | AC | 127 ms | 9296 KB |
1_46.txt | AC | 130 ms | 9556 KB |
1_47.txt | AC | 121 ms | 9684 KB |
1_48.txt | AC | 123 ms | 9684 KB |
1_49.txt | AC | 124 ms | 10324 KB |
1_50.txt | AC | 116 ms | 9172 KB |
1_51.txt | AC | 116 ms | 9296 KB |
1_52.txt | AC | 118 ms | 9428 KB |
1_53.txt | AC | 117 ms | 9172 KB |
1_54.txt | AC | 131 ms | 10320 KB |
1_55.txt | AC | 118 ms | 9556 KB |
1_56.txt | AC | 129 ms | 10704 KB |
1_57.txt | AC | 122 ms | 10320 KB |
1_58.txt | AC | 117 ms | 9168 KB |
1_59.txt | AC | 116 ms | 9168 KB |
1_60.txt | AC | 116 ms | 9168 KB |
1_61.txt | AC | 121 ms | 9168 KB |
1_62.txt | AC | 131 ms | 9684 KB |
1_63.txt | AC | 130 ms | 10832 KB |
1_64.txt | AC | 118 ms | 9684 KB |
1_65.txt | AC | 135 ms | 10320 KB |
1_66.txt | AC | 118 ms | 9296 KB |
1_67.txt | AC | 127 ms | 9300 KB |
1_68.txt | AC | 128 ms | 9296 KB |
1_69.txt | AC | 117 ms | 9168 KB |
1_70.txt | AC | 129 ms | 10760 KB |
1_71.txt | AC | 117 ms | 10196 KB |