結果
問題 | No.803 Very Limited Xor Subset |
ユーザー | maspy |
提出日時 | 2020-04-14 22:22:09 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 519 ms / 2,000 ms |
コード長 | 1,539 bytes |
コンパイル時間 | 287 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 44,108 KB |
最終ジャッジ日時 | 2024-10-01 18:16:35 |
合計ジャッジ時間 | 25,253 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 519 ms
43,824 KB |
testcase_01 | AC | 448 ms
43,568 KB |
testcase_02 | AC | 440 ms
43,976 KB |
testcase_03 | AC | 435 ms
43,952 KB |
testcase_04 | AC | 439 ms
43,980 KB |
testcase_05 | AC | 438 ms
43,980 KB |
testcase_06 | AC | 452 ms
43,564 KB |
testcase_07 | AC | 451 ms
44,084 KB |
testcase_08 | AC | 439 ms
43,692 KB |
testcase_09 | AC | 435 ms
43,568 KB |
testcase_10 | AC | 439 ms
43,848 KB |
testcase_11 | AC | 457 ms
44,104 KB |
testcase_12 | AC | 449 ms
43,948 KB |
testcase_13 | AC | 462 ms
43,852 KB |
testcase_14 | AC | 484 ms
43,972 KB |
testcase_15 | AC | 441 ms
44,104 KB |
testcase_16 | AC | 439 ms
43,572 KB |
testcase_17 | AC | 440 ms
43,696 KB |
testcase_18 | AC | 436 ms
43,716 KB |
testcase_19 | AC | 447 ms
43,724 KB |
testcase_20 | AC | 450 ms
43,708 KB |
testcase_21 | AC | 446 ms
43,976 KB |
testcase_22 | AC | 436 ms
43,824 KB |
testcase_23 | AC | 438 ms
43,820 KB |
testcase_24 | AC | 438 ms
44,084 KB |
testcase_25 | AC | 436 ms
44,008 KB |
testcase_26 | AC | 438 ms
44,104 KB |
testcase_27 | AC | 436 ms
44,096 KB |
testcase_28 | AC | 442 ms
43,980 KB |
testcase_29 | AC | 436 ms
44,084 KB |
testcase_30 | AC | 441 ms
43,828 KB |
testcase_31 | AC | 440 ms
43,688 KB |
testcase_32 | AC | 444 ms
44,076 KB |
testcase_33 | AC | 446 ms
44,080 KB |
testcase_34 | AC | 448 ms
43,844 KB |
testcase_35 | AC | 447 ms
43,976 KB |
testcase_36 | AC | 448 ms
43,980 KB |
testcase_37 | AC | 442 ms
43,692 KB |
testcase_38 | AC | 454 ms
44,108 KB |
testcase_39 | AC | 439 ms
43,952 KB |
testcase_40 | AC | 440 ms
43,692 KB |
testcase_41 | AC | 444 ms
44,104 KB |
testcase_42 | AC | 441 ms
43,848 KB |
testcase_43 | AC | 438 ms
43,972 KB |
testcase_44 | AC | 447 ms
43,984 KB |
testcase_45 | AC | 439 ms
43,560 KB |
testcase_46 | AC | 440 ms
43,956 KB |
ソースコード
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N, M, X = map(int, readline().split()) A = list(map(int, readline().split())) + [0] A = [0] + [x ^ y for x, y in zip(A, A[1:])] m = map(int, read().split()) graph = [[] for _ in range(N + 1)] for t, x, y in zip(m, m, m): x -= 1 graph[x].append((y, t)) graph[y].append((x, t)) C = [0] * (N + 1) root = [-1] * (N + 1) is_ng = False for v in range(N + 1): if root[v] != -1: continue stack = [v] root[v] = v while stack: v = stack.pop() for w, x in graph[v]: if root[w] == -1: root[w] = root[v] C[w] = C[v] ^ x stack.append(w) continue if C[w] != C[v] ^ x: is_ng = True if is_ng: print(0) exit() for v in range(N + 1): X ^= C[v] * A[v] if v != root[v]: A[root[v]] ^= A[v] def row_transform_over_F2(A, highest=60): for k in range(highest, -1, -1): I = np.where((A >> k) == 1)[0] if len(I) == 0: continue i = I[0] x = A[i] A ^= ((A >> k) & 1) * x A[i] = x nums = np.array([A[v] for v in range(N + 1) if v == root[v] != 0], np.int32) row_transform_over_F2(nums, 31) nums.sort() nums = nums[::-1] for x in nums: if x <= X: X ^= x if X != 0: print(0) else: MOD = 10 ** 9 + 7 free = int(np.sum(nums == 0)) print(pow(2, free, MOD))