結果
問題 | No.1881 Everything is the same... |
ユーザー | cologne |
提出日時 | 2022-03-18 02:55:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 374 ms / 2,000 ms |
コード長 | 2,506 bytes |
コンパイル時間 | 328 ms |
コンパイル使用メモリ | 82,168 KB |
実行使用メモリ | 82,768 KB |
最終ジャッジ日時 | 2024-10-02 13:33:20 |
合計ジャッジ時間 | 13,865 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
55,296 KB |
testcase_01 | AC | 50 ms
55,296 KB |
testcase_02 | AC | 48 ms
55,424 KB |
testcase_03 | AC | 49 ms
55,296 KB |
testcase_04 | AC | 47 ms
55,296 KB |
testcase_05 | AC | 54 ms
55,296 KB |
testcase_06 | AC | 188 ms
78,932 KB |
testcase_07 | AC | 46 ms
55,296 KB |
testcase_08 | AC | 48 ms
54,912 KB |
testcase_09 | AC | 48 ms
55,040 KB |
testcase_10 | AC | 327 ms
80,504 KB |
testcase_11 | AC | 313 ms
81,392 KB |
testcase_12 | AC | 351 ms
81,324 KB |
testcase_13 | AC | 338 ms
81,088 KB |
testcase_14 | AC | 366 ms
81,776 KB |
testcase_15 | AC | 368 ms
81,680 KB |
testcase_16 | AC | 354 ms
81,356 KB |
testcase_17 | AC | 348 ms
80,316 KB |
testcase_18 | AC | 342 ms
81,472 KB |
testcase_19 | AC | 374 ms
82,740 KB |
testcase_20 | AC | 356 ms
82,064 KB |
testcase_21 | AC | 340 ms
80,668 KB |
testcase_22 | AC | 341 ms
81,252 KB |
testcase_23 | AC | 351 ms
80,912 KB |
testcase_24 | AC | 345 ms
81,000 KB |
testcase_25 | AC | 340 ms
81,028 KB |
testcase_26 | AC | 336 ms
80,964 KB |
testcase_27 | AC | 345 ms
81,100 KB |
testcase_28 | AC | 333 ms
80,772 KB |
testcase_29 | AC | 334 ms
80,980 KB |
testcase_30 | AC | 361 ms
82,768 KB |
testcase_31 | AC | 350 ms
81,488 KB |
testcase_32 | AC | 323 ms
80,884 KB |
testcase_33 | AC | 360 ms
81,996 KB |
testcase_34 | AC | 373 ms
81,428 KB |
testcase_35 | AC | 357 ms
81,908 KB |
testcase_36 | AC | 336 ms
80,940 KB |
testcase_37 | AC | 352 ms
81,224 KB |
testcase_38 | AC | 347 ms
81,868 KB |
testcase_39 | AC | 358 ms
82,124 KB |
testcase_40 | AC | 351 ms
81,796 KB |
testcase_41 | AC | 344 ms
80,872 KB |
testcase_42 | AC | 48 ms
55,296 KB |
testcase_43 | AC | 48 ms
54,912 KB |
testcase_44 | AC | 47 ms
55,424 KB |
testcase_45 | AC | 49 ms
55,296 KB |
testcase_46 | AC | 48 ms
55,296 KB |
testcase_47 | AC | 47 ms
55,296 KB |
testcase_48 | AC | 47 ms
55,296 KB |
testcase_49 | AC | 47 ms
55,296 KB |
testcase_50 | AC | 47 ms
55,040 KB |
testcase_51 | AC | 48 ms
55,424 KB |
ソースコード
from functools import reduce from itertools import count from operator import xor def factorize(N): ret = [] for p in count(2): if p*p > N: break if N % p == 0: k = 0 while N % p == 0: k += 1 N //= p ret.append((p, k)) if N != 1: ret.append((N, 1)) return ret memo = {} def bktk(A): if len(A) == 0: yield [] return for i in range(A[-1]): for a in bktk(A[:-1]): a.append(i) yield a return def calc(A): # Calculate grundy number of cyclic group, prod(Cp^a) # A should be sorted if A in memo: return memo[A] if len(A) == 0: return 0 grundy = set() # for group C = prod(Cp^ai), backtrack for B / <x> # B = prod(Cp^bi), then a_{i-1} <= b_i <= a_i holds. # this means, 0 <= ai-bi <= a_i-a_{i-1} cA = [1 + A[i] - (0 if i == 0 else A[i-1]) for i in range(len(A))] for dA in bktk(cA): if max(dA) == 0: continue B = tuple(a-da for a, da in zip(A, dA) if a != da) grundy.add(calc(B)) for i in count(0): if i not in grundy: memo[A] = i return i def solve(x): # express G as product of cyclic group # C[p] = [a, b, ...] denotes (Z/xZ)* = Cp^a*Cp^b*... C = {} for p, k in factorize(x): if p not in C: C[p] = [] if p == 2: if k >= 2: C[p].append(1) if k >= 3: C[p].append(k-2) else: if k >= 2: C[p].append(k-1) for q, t in factorize(p-1): if q not in C: C[q] = [] C[q].append(t) # simple transpose algorithm def T(arr): if len(arr) == 0: return () ret = [0] * max(arr) for i in arr: for j in range(i): ret[j] += 1 return tuple(ret) # Here, uses transpose trick. # grundy number of cyclic group quotient can be transposed into game where # arbitary positive number of decks were chosen, and -1 from chosen numbers part = [] for v in C.values(): part.extend(T(v)) part = T(part) return calc(part[::-1]) def main(): int(input()) # N A = map(int, input().split()) G = reduce(xor, map(solve, A)) print('X' if G == 0 else 'Y') if __name__ == '__main__': main()