結果

問題 No.1881 Everything is the same...
ユーザー 37zigen37zigen
提出日時 2022-02-10 07:29:41
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 4,360 bytes
コンパイル時間 2,822 ms
コンパイル使用メモリ 86,724 KB
実行使用メモリ 78,616 KB
最終ジャッジ日時 2024-04-10 11:33:31
合計ジャッジ時間 19,480 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 311 ms
77,184 KB
testcase_07 AC 219 ms
66,432 KB
testcase_08 AC 181 ms
66,248 KB
testcase_09 AC 235 ms
66,360 KB
testcase_10 WA -
testcase_11 AC 270 ms
69,436 KB
testcase_12 AC 371 ms
76,136 KB
testcase_13 AC 307 ms
78,000 KB
testcase_14 AC 322 ms
76,268 KB
testcase_15 AC 371 ms
76,940 KB
testcase_16 AC 342 ms
76,884 KB
testcase_17 AC 337 ms
76,416 KB
testcase_18 AC 312 ms
76,720 KB
testcase_19 AC 328 ms
76,544 KB
testcase_20 AC 333 ms
76,724 KB
testcase_21 AC 300 ms
75,752 KB
testcase_22 AC 299 ms
75,952 KB
testcase_23 AC 303 ms
75,024 KB
testcase_24 AC 312 ms
76,124 KB
testcase_25 AC 371 ms
76,204 KB
testcase_26 AC 331 ms
75,768 KB
testcase_27 AC 382 ms
76,888 KB
testcase_28 AC 369 ms
76,296 KB
testcase_29 AC 309 ms
76,972 KB
testcase_30 AC 313 ms
77,472 KB
testcase_31 AC 401 ms
75,928 KB
testcase_32 WA -
testcase_33 AC 333 ms
75,768 KB
testcase_34 AC 375 ms
75,660 KB
testcase_35 AC 301 ms
75,324 KB
testcase_36 AC 362 ms
75,980 KB
testcase_37 AC 308 ms
77,256 KB
testcase_38 AC 306 ms
76,096 KB
testcase_39 AC 417 ms
78,616 KB
testcase_40 AC 313 ms
75,500 KB
testcase_41 AC 314 ms
76,556 KB
testcase_42 AC 210 ms
66,140 KB
testcase_43 AC 189 ms
66,620 KB
testcase_44 AC 203 ms
66,488 KB
testcase_45 AC 215 ms
66,340 KB
testcase_46 AC 196 ms
66,244 KB
testcase_47 AC 185 ms
66,240 KB
testcase_48 AC 183 ms
66,504 KB
testcase_49 AC 228 ms
66,324 KB
testcase_50 AC 217 ms
66,448 KB
testcase_51 AC 246 ms
66,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// かならいさんの指数の nim という嘘解

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;

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));
			}
		}
	}
	
	int grundy(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);
				}
			}
		}
		int g=0;
		for (var entryset : decode.entrySet()) {
			int[] key=new int[20];
			for (int i=0;i<entryset.getValue().size();++i) {
				key[i]=entryset.getValue().get(i);
			}
			Arrays.sort(key);
			{
				int sub=0;
				for (int v : key) sub^=v;
				g+=sub;
			}
		}
		return g;
	}
	
	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;
	}
	
	
	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();
    }
}
0