Submission #5011062


Source Code Expand

# -*- coding: utf-8 -*-

import sys
from functools import reduce
from operator import xor

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=[INT() for i in range(N)]

mnbit=set()
for i, a in enumerate(A):
    bina=format(a, 'b')
    # 2進で最初に1になる桁を、各値について見る
    mnbit.add(len(bina)-bina.rfind('1'))

# 現状のA全部XOR
res=format(reduce(xor, A, 0), 'b')
cnt=0
ln=len(res)
for i in range(ln):
    idx=ln-i
    # 大きい桁から見て、1になっているところについて処理する
    if res[i]=='1':
        # その桁用の値があるか
        if idx in mnbit:
            # あればそれを1減らせば、その桁より下が全部反転する
            res=format(int(res, 2)^int('1'*idx, 2), '0'+str(ln)+'b')
            cnt+=1
        else:
            # 必要な桁用の値がなければNG
            print(-1)
            exit()
print(cnt)

Submission Info

Submission Time
Task C - Cheating Nim
User Coki628
Language Python (3.4.3)
Score 500
Code Size 1433 Byte
Status AC
Exec Time 180 ms
Memory 7656 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 26
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 23 ms 3572 KB
001.txt AC 23 ms 3572 KB
002.txt AC 169 ms 7612 KB
003.txt AC 111 ms 5588 KB
004.txt AC 94 ms 5476 KB
005.txt AC 66 ms 4796 KB
006.txt AC 170 ms 7552 KB
007.txt AC 171 ms 7552 KB
008.txt AC 170 ms 7552 KB
009.txt AC 176 ms 7656 KB
010.txt AC 176 ms 7612 KB
011.txt AC 178 ms 7552 KB
012.txt AC 180 ms 7656 KB
013.txt AC 173 ms 7600 KB
014.txt AC 169 ms 7612 KB
015.txt AC 171 ms 7656 KB
016.txt AC 171 ms 7656 KB
017.txt AC 173 ms 7656 KB
018.txt AC 173 ms 7656 KB
019.txt AC 174 ms 7552 KB
020.txt AC 178 ms 7656 KB
021.txt AC 36 ms 3932 KB
022.txt AC 36 ms 3932 KB
023.txt AC 171 ms 7656 KB
example0.txt AC 23 ms 3572 KB
example1.txt AC 23 ms 3572 KB