Submission #5011093
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=reduce(xor, A, 0) ln=len(format(res, 'b')) cnt=0 for i in range(ln): idx=ln-i # 大きい桁から見て、1になっているところについて処理する if res>>(idx-1)&1: # その桁用の値があるか if idx in mnbit: # あればそれを1減らせば、その桁より下が全部反転する(1111..とXORする) res^=(1<<idx)-1 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 | 1415 Byte |
Status | AC |
Exec Time | 179 ms |
Memory | 7656 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
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 | 3804 KB |
001.txt | AC | 23 ms | 3572 KB |
002.txt | AC | 171 ms | 7576 KB |
003.txt | AC | 115 ms | 5592 KB |
004.txt | AC | 92 ms | 5476 KB |
005.txt | AC | 66 ms | 4856 KB |
006.txt | AC | 176 ms | 7656 KB |
007.txt | AC | 170 ms | 7656 KB |
008.txt | AC | 169 ms | 7656 KB |
009.txt | AC | 171 ms | 7576 KB |
010.txt | AC | 172 ms | 7656 KB |
011.txt | AC | 169 ms | 7656 KB |
012.txt | AC | 170 ms | 7656 KB |
013.txt | AC | 171 ms | 7656 KB |
014.txt | AC | 174 ms | 7656 KB |
015.txt | AC | 177 ms | 7656 KB |
016.txt | AC | 179 ms | 7656 KB |
017.txt | AC | 176 ms | 7576 KB |
018.txt | AC | 172 ms | 7576 KB |
019.txt | AC | 169 ms | 7656 KB |
020.txt | AC | 169 ms | 7656 KB |
021.txt | AC | 36 ms | 3932 KB |
022.txt | AC | 36 ms | 3932 KB |
023.txt | AC | 176 ms | 7656 KB |
example0.txt | AC | 23 ms | 3572 KB |
example1.txt | AC | 23 ms | 3572 KB |