Contest Duration: - (local time) (180 minutes)

Submission #18296184

Source Code Expand

Copy
```import sys
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

"""ビット行列
1次方程式、ランクrank
"""
class BitMatrix:
def __init__(self, h, w, v=None):
self.h = h
self.w = w
self.l = [0]*h
if v is not None:
for i in range(h):
for j in range(w):
if v[i][j]:
self.l[i] |= (1<<j)
def to_matrix(self):
M = []
for i in range(self.h):
l = []
for j in range(self.w):
l.append(self.l[i]>>j&1)
M.append(l)
return M
def swap(self, i, j):
"""i行目とj行目のスワップ
"""
self.l[i], self.l[j] = self.l[j], self.l[i]
def __getitem__(self, args):
if not hasattr(args, "__getitem__"):
return self.l[args]
else:
assert args[1]<self.w
return (self.l[args[0]]>>args[1])&1
def __setitem__(self, args, v):
if not hasattr(args, "__getitem__"):
self.l[args] = v
else:
assert args[1]<self.w
if v:
self.l[args[0]] |= (1<<args[1])
elif self.l[args[0]]>>args[1]&1:
self.l[args[0]] -= (1<<args[1])

def GaussJordan(A, is_extended=False):
"""A: BitMatrix (H*W)
"""
rank = 0
H = A.h
W = A.w
ww = W if not is_extended else W-1
for col in range(ww):
pivot = -1
for row in range(rank, H):
if A[row,col]:
pivot = row
break
if pivot==-1:
continue
#         A[pivot], A[rank] = A[rank], A[pivot]
A.swap(pivot, rank)
for row in range(H):
if (row!=rank and A[row,col]):
val = A[row] ^ A[rank]
A[row] = val
rank += 1
return rank

def solve(A, b):
"""A: Matrix (m*n), b: array (n*1)
解がある場合、そのひとつresと解区間の次元rankを返す
ない場合はNone,-1を返す
"""
if isinstance(A, list):
A = BitMatrix(len(A), len(A[0]), A)
m = A.h
n = A.w
M = BitMatrix(m,n+1)
for i in range(m):
for j in range(n):
M[i,j] = A[i,j]
M[i,n] = b[i]
rank = GaussJordan(M, True)
for row in range(rank, m):
if M[row,n]:
# 解なし
return None, -1
res = [0]*n
for i in range(rank):
res[i] = M[i,n]
return res, rank

n,x = list(map(int, input().split()))
a = [int(input()) for _ in range(n)]
A = []
b = []
mm = max(x, max(a))
# d = mm.bit_length()
d = 32
for i in range(d):
tmp = []
for j in range(n):
tmp.append((a[j]>>i)&1)
A.append(tmp)
b.append((x>>i)&1)
res, rank = solve(A, b)
if rank==-1:
ans = 0
else:
M = 10**9+7
ans = pow(2, n-rank, M)
print(ans)```

#### Submission Info

Submission Time 2020-11-22 15:48:23+0900 F - Limited Xor Subset shotoyoo PyPy3 (7.3.0) 500 3057 Byte AC 923 ms 156648 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
 AC × 3
 AC × 33
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
sample_01.txt AC 74 ms 62828 KB
sample_02.txt AC 55 ms 62628 KB
sample_03.txt AC 52 ms 62900 KB
subtask_1_1.txt AC 55 ms 63052 KB
subtask_1_10.txt AC 100 ms 69232 KB
subtask_1_11.txt AC 88 ms 68356 KB
subtask_1_12.txt AC 62 ms 68232 KB
subtask_1_13.txt AC 71 ms 68084 KB
subtask_1_14.txt AC 55 ms 63256 KB
subtask_1_15.txt AC 55 ms 63340 KB
subtask_1_16.txt AC 52 ms 62984 KB
subtask_1_17.txt AC 56 ms 62760 KB
subtask_1_18.txt AC 541 ms 127400 KB
subtask_1_19.txt AC 247 ms 92720 KB
subtask_1_2.txt AC 58 ms 63344 KB
subtask_1_20.txt AC 88 ms 68996 KB
subtask_1_21.txt AC 87 ms 69072 KB
subtask_1_22.txt AC 52 ms 62692 KB
subtask_1_23.txt AC 47 ms 62724 KB
subtask_1_24.txt AC 51 ms 62532 KB
subtask_1_25.txt AC 923 ms 156648 KB
subtask_1_26.txt AC 92 ms 68816 KB
subtask_1_27.txt AC 50 ms 62460 KB
subtask_1_28.txt AC 56 ms 62620 KB
subtask_1_29.txt AC 58 ms 62744 KB
subtask_1_3.txt AC 56 ms 63320 KB
subtask_1_30.txt AC 54 ms 62748 KB
subtask_1_4.txt AC 54 ms 63216 KB
subtask_1_5.txt AC 55 ms 63020 KB
subtask_1_6.txt AC 349 ms 93908 KB
subtask_1_7.txt AC 133 ms 72660 KB
subtask_1_8.txt AC 94 ms 69668 KB
subtask_1_9.txt AC 85 ms 68756 KB