結果
問題 | No.1881 Everything is the same... |
ユーザー | 37zigen |
提出日時 | 2022-03-18 22:04:08 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 741 ms / 2,000 ms |
コード長 | 7,842 bytes |
コンパイル時間 | 2,496 ms |
コンパイル使用メモリ | 94,512 KB |
実行使用メモリ | 84,356 KB |
最終ジャッジ日時 | 2024-10-03 06:51:36 |
合計ジャッジ時間 | 29,404 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 203 ms
66,472 KB |
testcase_01 | AC | 196 ms
66,464 KB |
testcase_02 | AC | 177 ms
66,260 KB |
testcase_03 | AC | 190 ms
66,228 KB |
testcase_04 | AC | 188 ms
66,456 KB |
testcase_05 | AC | 196 ms
66,172 KB |
testcase_06 | AC | 332 ms
77,204 KB |
testcase_07 | AC | 170 ms
66,216 KB |
testcase_08 | AC | 193 ms
66,308 KB |
testcase_09 | AC | 194 ms
66,584 KB |
testcase_10 | AC | 675 ms
80,100 KB |
testcase_11 | AC | 724 ms
80,352 KB |
testcase_12 | AC | 669 ms
80,116 KB |
testcase_13 | AC | 632 ms
80,576 KB |
testcase_14 | AC | 715 ms
79,944 KB |
testcase_15 | AC | 635 ms
80,456 KB |
testcase_16 | AC | 652 ms
79,704 KB |
testcase_17 | AC | 719 ms
83,904 KB |
testcase_18 | AC | 617 ms
80,244 KB |
testcase_19 | AC | 658 ms
80,144 KB |
testcase_20 | AC | 643 ms
80,304 KB |
testcase_21 | AC | 741 ms
80,400 KB |
testcase_22 | AC | 651 ms
80,216 KB |
testcase_23 | AC | 700 ms
80,388 KB |
testcase_24 | AC | 709 ms
80,844 KB |
testcase_25 | AC | 649 ms
80,272 KB |
testcase_26 | AC | 730 ms
80,928 KB |
testcase_27 | AC | 665 ms
80,268 KB |
testcase_28 | AC | 656 ms
80,380 KB |
testcase_29 | AC | 699 ms
84,356 KB |
testcase_30 | AC | 667 ms
80,748 KB |
testcase_31 | AC | 693 ms
79,912 KB |
testcase_32 | AC | 677 ms
80,204 KB |
testcase_33 | AC | 628 ms
80,400 KB |
testcase_34 | AC | 631 ms
80,104 KB |
testcase_35 | AC | 691 ms
80,760 KB |
testcase_36 | AC | 668 ms
80,076 KB |
testcase_37 | AC | 695 ms
79,968 KB |
testcase_38 | AC | 613 ms
80,336 KB |
testcase_39 | AC | 697 ms
80,116 KB |
testcase_40 | AC | 675 ms
80,176 KB |
testcase_41 | AC | 706 ms
80,248 KB |
testcase_42 | AC | 196 ms
66,380 KB |
testcase_43 | AC | 180 ms
66,340 KB |
testcase_44 | AC | 207 ms
66,248 KB |
testcase_45 | AC | 173 ms
66,340 KB |
testcase_46 | AC | 192 ms
66,576 KB |
testcase_47 | AC | 210 ms
66,620 KB |
testcase_48 | AC | 177 ms
66,068 KB |
testcase_49 | AC | 205 ms
66,400 KB |
testcase_50 | AC | 203 ms
66,500 KB |
testcase_51 | AC | 190 ms
66,332 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)1e5+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=new int[bits][bits]; for (int i=0;i<bits;++i)for(int j=0;j<bits;++j) key[i][j]=na[i][j]; normalize(key); int g=grundy(key); vis[g]=true; ++cnt; } } // 90 まで確かめた。 void run() { solve(); } void solve() { FastScanner sc=new FastScanner(); int N=sc.nextInt(); if (!(1 <= N && N <= 1e4)) throw new AssertionError(); int[] A=new int[N]; int g=0; for (int i=0;i<N;++i) { A[i]=sc.nextInt(); if (!(1 <= A[i] && A[i] <= 1e5)) throw new AssertionError(); g^=grundy(A[i]); } System.out.println(g==0?"X":"Y"); } static void tr(Object...objects) { System.out.println(Arrays.deepToString(objects)); } } class BruteForce { 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) { if (o1[i] != o2[i]) return Integer.compare(o1[i], o2[i]); } return 0; } }); int calc(int n) { DSU dsu=new DSU(n+1); return grundy(n, dsu); } int grundy(int n, DSU dsu) { if (set.containsKey(dsu.parent)) return set.get(dsu.parent); boolean[] vis=new boolean[20]; for (int add=2;add<n;++add) { if (gcd(add, n) != 1) continue; boolean ok=false; DSU ndsu=dsu.copy(); for (int i=1;i<=n;++i) { for (int j=1;j<=n;++j) { if (!dsu.equiv(i, j) && i*add%n==j) { ndsu.union(i, j); ok=true; } } } if (ok) vis[grundy(n, ndsu)] = true; } int g=0; while (vis[g])++g; set.put(dsu.parent, g); return g; } int gcd(int a, int b) { if (a==0) return b; return gcd(b%a, a); } } class DSU { int[] parent; public DSU(int n) { parent=new int[n]; Arrays.fill(parent, -1); } int root(int x) { return parent[x] < 0 ? x : (parent[x]=root(parent[x])); } void union(int x, int y) { x=root(x); y=root(y); if (x==y) return; parent[y]+=parent[x]; parent[x]=y; } boolean equiv(int x, int y) { return root(x)==root(y); } int size(int x) { return -parent[root(x)]; } DSU copy() { DSU dsu=new DSU(parent.length); dsu.parent=this.parent.clone(); return dsu; } } 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(); } }