結果

問題 No.1881 Everything is the same...
ユーザー lam6er
提出日時 2025-04-15 22:56:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,649 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 77,244 KB
最終ジャッジ日時 2025-04-15 22:58:06
合計ジャッジ時間 4,877 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def factorize(n):
    factors = []
    count = 0
    while n % 2 == 0:
        count += 1
        n //= 2
    if count > 0:
        factors.append((2, count))
    i = 3
    while i * i <= n:
        if n % i == 0:
            count = 0
            while n % i == 0:
                count += 1
                n //= i
            factors.append((i, count))
        i += 2
    if n > 1:
        factors.append((n, 1))
    return factors

def main():
    input = sys.stdin.read().split()
    n = int(input[0])
    A = list(map(int, input[1:n+1]))
    
    total_xor = 0
    count_non_zero = 0
    
    for a in A:
        if a == 1 or a == 2:
            nimber = 0
        elif a == 4:
            nimber = 1
        else:
            factors = factorize(a)
            if len(factors) == 1:
                p, e = factors[0]
                if p == 2:
                    if e == 2:
                        nimber = 1
                    else:
                        nimber = 0
                else:
                    nimber = 1
            elif len(factors) == 2:
                if factors[0][0] == 2 and factors[0][1] == 1:
                    p, e = factors[1]
                    if p % 2 == 1 and e >= 1:
                        nimber = 1
                    else:
                        nimber = 0
                else:
                    nimber = 0
            else:
                nimber = 0
        total_xor ^= nimber
        if nimber != 0:
            count_non_zero += 1
    
    if count_non_zero == 0:
        print('X')
    else:
        print('X' if total_xor != 0 else 'Y')

if __name__ == '__main__':
    main()
0