結果
問題 | No.1881 Everything is the same... |
ユーザー | 37zigen |
提出日時 | 2022-03-18 07:57:15 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,148 bytes |
コンパイル時間 | 3,491 ms |
コンパイル使用メモリ | 94,016 KB |
実行使用メモリ | 67,864 KB |
最終ジャッジ日時 | 2024-10-02 13:33:04 |
合計ジャッジ時間 | 10,517 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
40,296 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 90 ms
40,520 KB |
testcase_04 | WA | - |
testcase_05 | AC | 87 ms
40,400 KB |
testcase_06 | AC | 214 ms
46,104 KB |
testcase_07 | AC | 90 ms
40,480 KB |
testcase_08 | AC | 90 ms
40,520 KB |
testcase_09 | WA | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | AC | 88 ms
40,048 KB |
testcase_43 | AC | 89 ms
39,952 KB |
testcase_44 | AC | 86 ms
39,948 KB |
testcase_45 | AC | 88 ms
40,276 KB |
testcase_46 | WA | - |
testcase_47 | AC | 88 ms
40,216 KB |
testcase_48 | WA | - |
testcase_49 | AC | 91 ms
40,844 KB |
testcase_50 | AC | 89 ms
40,180 KB |
testcase_51 | AC | 92 ms
40,708 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.NoSuchElementException; import java.util.TreeMap; class Main { public static void main(String[] args) { new Main().run(); } int MAX=(int)1e4+1; boolean[] isPrime=new boolean[MAX]; ArrayList<Integer> primes=new ArrayList<>(); ArrayList<List<Integer>>[] pe=new ArrayList[MAX]; { for (int i=0;i<pe.length;++i) pe[i]=new ArrayList<>(); Arrays.fill(isPrime, true); isPrime[0]=isPrime[1]=false; for (int i=2;i<MAX;++i) { if (!isPrime[i]) continue; primes.add(i); for (int j=i;j<MAX;j+=i) { if (j>i) isPrime[j]=false; int e=0; int v=j; while (v%i==0) { v/=i; ++e; } pe[j].add(List.of(i, e)); } } } HashMap<Integer, ArrayList<Integer>> cyclic_group(int n) { HashMap<Integer, ArrayList<Integer>> decode=new HashMap<>(); for (var pair : pe[n]) { int p=pair.get(0); int e=pair.get(1); if (p != 2) { if (e >= 2) decode.computeIfAbsent(p, key -> new ArrayList<>()).add(e-1); for (var pair2 : pe[p-1]) { int p2=pair2.get(0); int e2=pair2.get(1); decode.computeIfAbsent(p2, key -> new ArrayList<>()).add(e2); } } else { if (e == 2) { decode.computeIfAbsent(p, key -> new ArrayList<>()).add(1); } else if (e >= 3){ decode.computeIfAbsent(p, key -> new ArrayList<>()).add(e-2); decode.computeIfAbsent(p, key -> new ArrayList<>()).add(1); } } } return decode; } void normalize(int[][] key) { for (int i=0;i<key.length;++i) Arrays.sort(key[i]); Arrays.sort(key, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { for (int i=0;i<o1.length;++i) if (o1[i]!=o2[i]) return Integer.compare(o1[i], o2[i]); return 0; } }); } int[][] compressed_state(int n) { var decode=cyclic_group(n); int[][] key=new int[bits][bits]; int size=0; for (var entryset : decode.entrySet()) { for (int i=0;i<entryset.getValue().size();++i) { key[size][i]=entryset.getValue().get(i); } ++size; } normalize(key); return key; } int count(int n) { var decode=cyclic_group(n); int g=0; int[][] key=new int[bits][bits]; int size=0; for (var entryset : decode.entrySet()) { for (int i=0;i<entryset.getValue().size();++i) { key[size][i]=entryset.getValue().get(i); } ++size; } normalize(key); set.put(key, -1); return g; } TreeMap<int[][], Integer> set=new TreeMap<>(new Comparator<int[][]>() { @Override public int compare(int[][] o1, int[][] o2) { for (int i=0;i<o1.length;++i) { for (int j=0;j<o1[i].length;++j) { if (o1[i][j] != o2[i][j]) return Integer.compare(o1[i][j], o2[i][j]); } } return 0; } }); long pow(long a, long n) { if (n==0) return 1; return pow(a*a, n/2) * (n%2==1? a : 1) ; } long hash(int[] a) { long ret=1; for (int i=0;i<a.length;++i) { ret*=pow(primes.get(i), a[a.length-1-i]); } return ret; } int bits=6; int grundy(int a) { return grundy(compressed_state(a)); } int grundy(int[][] a) { if (set.containsKey(a)) return set.get(a); boolean[] vis=new boolean[17]; int[][] na=new int[bits][bits]; dfs(a, na, vis, 0, false); int g=0; while (vis[g]) ++g; set.put(a, g); return g; } int cnt=0; void dfs(int[][] a, int[][] na, boolean[] vis, int pos, boolean less) { if (pos <= a.length*a[0].length-1) { int pi=pos/a[0].length; int pj=pos%a[0].length; for (int i= pj == 0 ? 0 : a[pi][pj-1];i<=a[pi][pj];++i) { na[pi][pj]=i; dfs(a, na, vis, pos+1, less | i < a[pi][pj]); } } else { if (!less) return; int[][] key=na.clone(); normalize(key); vis[grundy(key)]=true; ++cnt; } } void run() { solve(); } void solve() { FastScanner sc=new FastScanner(); int N=sc.nextInt(); int[] A=new int[N]; int g=0; for (int i=0;i<N;++i) { A[i]=sc.nextInt(); g^=grundy(A[i]); } System.out.println(g==0?"X":"Y"); } static void tr(Object...objects) { System.out.println(Arrays.deepToString(objects)); } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;} public boolean hasNext() { skipUnprintable(); return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { return (int)nextLong(); } }