結果
問題 | No.803 Very Limited Xor Subset |
ユーザー | 👑 rin204 |
提出日時 | 2023-11-23 18:15:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 72 ms / 2,000 ms |
コード長 | 1,931 bytes |
コンパイル時間 | 277 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 65,152 KB |
最終ジャッジ日時 | 2024-09-26 08:17:30 |
合計ジャッジ時間 | 4,716 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
52,352 KB |
testcase_01 | AC | 49 ms
52,480 KB |
testcase_02 | AC | 48 ms
52,480 KB |
testcase_03 | AC | 48 ms
52,480 KB |
testcase_04 | AC | 48 ms
52,352 KB |
testcase_05 | AC | 49 ms
52,736 KB |
testcase_06 | AC | 49 ms
52,096 KB |
testcase_07 | AC | 48 ms
52,096 KB |
testcase_08 | AC | 48 ms
52,480 KB |
testcase_09 | AC | 48 ms
52,224 KB |
testcase_10 | AC | 49 ms
52,608 KB |
testcase_11 | AC | 50 ms
52,608 KB |
testcase_12 | AC | 49 ms
52,224 KB |
testcase_13 | AC | 47 ms
52,480 KB |
testcase_14 | AC | 65 ms
64,384 KB |
testcase_15 | AC | 63 ms
63,744 KB |
testcase_16 | AC | 64 ms
64,256 KB |
testcase_17 | AC | 70 ms
64,256 KB |
testcase_18 | AC | 63 ms
64,256 KB |
testcase_19 | AC | 62 ms
64,128 KB |
testcase_20 | AC | 65 ms
65,152 KB |
testcase_21 | AC | 64 ms
64,512 KB |
testcase_22 | AC | 63 ms
64,000 KB |
testcase_23 | AC | 51 ms
54,656 KB |
testcase_24 | AC | 65 ms
64,256 KB |
testcase_25 | AC | 64 ms
63,616 KB |
testcase_26 | AC | 63 ms
63,616 KB |
testcase_27 | AC | 66 ms
65,024 KB |
testcase_28 | AC | 66 ms
65,152 KB |
testcase_29 | AC | 66 ms
64,896 KB |
testcase_30 | AC | 67 ms
65,152 KB |
testcase_31 | AC | 64 ms
63,872 KB |
testcase_32 | AC | 64 ms
63,872 KB |
testcase_33 | AC | 65 ms
64,128 KB |
testcase_34 | AC | 48 ms
58,240 KB |
testcase_35 | AC | 65 ms
64,000 KB |
testcase_36 | AC | 54 ms
60,416 KB |
testcase_37 | AC | 57 ms
62,592 KB |
testcase_38 | AC | 54 ms
60,032 KB |
testcase_39 | AC | 59 ms
60,416 KB |
testcase_40 | AC | 71 ms
64,128 KB |
testcase_41 | AC | 59 ms
54,528 KB |
testcase_42 | AC | 72 ms
64,384 KB |
testcase_43 | AC | 57 ms
54,400 KB |
testcase_44 | AC | 50 ms
52,480 KB |
testcase_45 | AC | 51 ms
52,480 KB |
testcase_46 | AC | 56 ms
58,624 KB |
ソースコード
class UnionFind: def __init__(self, n): self.n = n self.par = [-1] * n self.group_ = n def find(self, x): if self.par[x] < 0: return x lst = [] while self.par[x] >= 0: lst.append(x) x = self.par[x] for y in lst: self.par[y] = x return x def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.par[x] > self.par[y]: x, y = y, x self.par[x] += self.par[y] self.par[y] = x self.group_ -= 1 return True def size(self, x): return -self.par[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) @property def group(self): return self.group_ n, m, x = map(int, input().split()) A = list(map(int, input().split())) T = [0] * m L = [0] * m R = [0] * m n += 1 UF = UnionFind(2 * n) for i in range(m): T[i], L[i], R[i] = map(int, input().split()) L[i] -= 1 if T[i] == 0: UF.unite(L[i], R[i]) UF.unite(L[i] + n, R[i] + n) else: UF.unite(L[i], R[i] + n) UF.unite(L[i] + n, R[i]) for i in range(n): if UF.same(i, i + n): print(0) exit() pari = [False] * n for i in range(n): pari[i] = UF.find(i) < n for i in range(n - 1): if pari[i] != pari[i + 1]: x ^= A[i] for i in range(n): UF.unite(i, i + n) X = {} for i in range(n): if UF.same(i, 0): continue r = UF.find(i) if i != 0: X[r] = X.get(r, 0) ^ A[i - 1] if i != n - 1: X[r] = X.get(r, 0) ^ A[i] bases = [] z = 0 for v in X.values(): for b in bases: v = min(v, v ^ b) if v == 0: z += 1 else: bases.append(v) for b in bases: x = min(x, x ^ b) if x == 0: print(pow(2, z, 10**9 + 7)) else: print(0)