QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#311968 | #5763. Cheating a Boolean Tree | mfshi03 | 0 | 40ms | 14892kb | Python3 | 1.1kb | 2024-01-23 03:39:41 | 2024-01-23 03:39:42 |
Judging History
answer
n = int(input())
def compute():
M, V = tuple(map(int, input().split()))
nodes = dict()
internal = set()
leaf = set()
for j in range(1, (M-1)//2 + 1):
bit, change = tuple(map(int, input().split()))
if change == 1 and bit == V:
bit = 1 if V == 0 else 0
nodes[j] = bit
internal.add(j)
for j in range((M-1)//2 + 1, M + 1):
nodes[j] = int(input())
leaf.add(j)
cache = dict()
def dfs(root):
if root in cache:
return cache[root]
if root in internal:
if nodes[root] == 1:
cache[root] = dfs(root * 2) & dfs(root * 2 + 1)
else:
cache[root] = dfs(root * 2) | dfs(root * 2 + 1)
else:
cache[root] = nodes[root]
return cache[root]
val = dfs(1)
if val == V:
return val
return "IMPOSSIBLE"
for i in range(n):
val = compute()
print(f"Case #{i+1}: {val}")
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 9964kb
input:
20 11 0 1 1 0 1 1 0 0 1 0 1 1 1 1 0 0 1 9 0 0 0 1 1 1 1 0 1 1 0 1 0 1 9 1 0 0 0 1 0 1 1 0 1 0 1 1 1 15 1 1 1 0 1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 0 1 19 1 1 1 0 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1 0 0 0 1 0 1 0 0 0 0 25 1 1 0 0 0 1 0 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 0 0 1 1 0 27 0 0 0 0 ...
output:
Case #1: 0 Case #2: 0 Case #3: 1 Case #4: 1 Case #5: IMPOSSIBLE Case #6: 1 Case #7: 0 Case #8: 0 Case #9: IMPOSSIBLE Case #10: 0 Case #11: 1 Case #12: 1 Case #13: IMPOSSIBLE Case #14: 0 Case #15: IMPOSSIBLE Case #16: 1 Case #17: 0 Case #18: 0 Case #19: 1 Case #20: IMPOSSIBLE
result:
wrong answer 1st lines differ - expected: 'Case #1: 2', found: 'Case #1: 0'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 40ms
memory: 14892kb
input:
20 1247 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 ...
output:
Case #1: 0 Case #2: 1 Case #3: 0 Case #4: 1 Case #5: 0 Case #6: 1 Case #7: 1 Case #8: 0 Case #9: IMPOSSIBLE Case #10: IMPOSSIBLE Case #11: IMPOSSIBLE Case #12: 1 Case #13: IMPOSSIBLE Case #14: 1 Case #15: 0 Case #16: 0 Case #17: IMPOSSIBLE Case #18: 0 Case #19: 1 Case #20: 0
result:
wrong answer 1st lines differ - expected: 'Case #1: 114', found: 'Case #1: 0'