結果
問題 | No.803 Very Limited Xor Subset |
ユーザー | shotoyoo |
提出日時 | 2020-11-22 15:13:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 137 ms / 2,000 ms |
コード長 | 3,095 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,516 KB |
実行使用メモリ | 78,120 KB |
最終ジャッジ日時 | 2024-07-23 16:32:58 |
合計ジャッジ時間 | 6,289 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,256 KB |
testcase_01 | AC | 38 ms
53,840 KB |
testcase_02 | AC | 38 ms
54,024 KB |
testcase_03 | AC | 41 ms
54,044 KB |
testcase_04 | AC | 44 ms
60,860 KB |
testcase_05 | AC | 44 ms
59,292 KB |
testcase_06 | AC | 42 ms
54,636 KB |
testcase_07 | AC | 41 ms
53,832 KB |
testcase_08 | AC | 42 ms
54,328 KB |
testcase_09 | AC | 41 ms
53,544 KB |
testcase_10 | AC | 44 ms
61,228 KB |
testcase_11 | AC | 44 ms
60,212 KB |
testcase_12 | AC | 47 ms
60,428 KB |
testcase_13 | AC | 43 ms
59,040 KB |
testcase_14 | AC | 126 ms
77,612 KB |
testcase_15 | AC | 124 ms
77,688 KB |
testcase_16 | AC | 121 ms
77,820 KB |
testcase_17 | AC | 121 ms
77,500 KB |
testcase_18 | AC | 119 ms
77,520 KB |
testcase_19 | AC | 131 ms
77,820 KB |
testcase_20 | AC | 126 ms
77,788 KB |
testcase_21 | AC | 127 ms
77,484 KB |
testcase_22 | AC | 125 ms
77,700 KB |
testcase_23 | AC | 132 ms
77,948 KB |
testcase_24 | AC | 133 ms
78,108 KB |
testcase_25 | AC | 132 ms
77,860 KB |
testcase_26 | AC | 133 ms
78,072 KB |
testcase_27 | AC | 134 ms
77,672 KB |
testcase_28 | AC | 135 ms
77,932 KB |
testcase_29 | AC | 133 ms
77,824 KB |
testcase_30 | AC | 132 ms
78,112 KB |
testcase_31 | AC | 133 ms
78,004 KB |
testcase_32 | AC | 130 ms
78,056 KB |
testcase_33 | AC | 130 ms
77,784 KB |
testcase_34 | AC | 80 ms
76,892 KB |
testcase_35 | AC | 136 ms
77,884 KB |
testcase_36 | AC | 118 ms
77,396 KB |
testcase_37 | AC | 122 ms
77,220 KB |
testcase_38 | AC | 66 ms
72,324 KB |
testcase_39 | AC | 65 ms
71,468 KB |
testcase_40 | AC | 128 ms
77,924 KB |
testcase_41 | AC | 134 ms
77,792 KB |
testcase_42 | AC | 137 ms
78,120 KB |
testcase_43 | AC | 126 ms
77,784 KB |
testcase_44 | AC | 39 ms
53,268 KB |
testcase_45 | AC | 39 ms
53,764 KB |
testcase_46 | AC | 57 ms
68,936 KB |
ソースコード
import sys input = lambda : sys.stdin.readline().rstrip() 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,m,x = list(map(int, input().split())) a = list(map(int, input().split())) 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) for i in range(m): tmp = [] t,l,r = map(int, input().split()) tmp = [0]*(l-1) + [1]*(r-l+1) + [0]*(n-r) A.append(tmp) b.append(t) res, rank = solve(A, b) if rank==-1: ans = 0 else: M = 10**9+7 ans = pow(2, n-rank, M) print(ans)