QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#311967#5763. Cheating a Boolean Treemfshi030 32ms14956kbPython31.1kb2024-01-23 03:38:482024-01-23 03:38:49

Judging History

你现在查看的是最新测评结果

  • [2024-01-23 03:38:49]
  • 评测
  • 测评结果:0
  • 用时:32ms
  • 内存:14956kb
  • [2024-01-23 03:38:48]
  • 提交

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)

    print(len(internal), len(leaf))
    
    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}")

        






    
    
    


详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 11ms
memory: 9808kb

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:

5 6
Case #1: 0
4 5
Case #2: 0
4 5
Case #3: 1
7 8
Case #4: 1
9 10
Case #5: IMPOSSIBLE
12 13
Case #6: 1
13 14
Case #7: 0
5 6
Case #8: 0
1 2
Case #9: IMPOSSIBLE
10 11
Case #10: 0
7 8
Case #11: 1
1 2
Case #12: 1
1 2
Case #13: IMPOSSIBLE
2 3
Case #14: 0
3 4
Case #15: IMPOSSIBLE
10 11
Case #16: 1
14 15
Ca...

result:

wrong answer 1st lines differ - expected: 'Case #1: 2', found: '5 6'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 32ms
memory: 14956kb

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:

623 624
Case #1: 0
4999 5000
Case #2: 1
144 145
Case #3: 0
50 51
Case #4: 1
28 29
Case #5: 0
365 366
Case #6: 1
1178 1179
Case #7: 1
518 519
Case #8: 0
21 22
Case #9: IMPOSSIBLE
336 337
Case #10: IMPOSSIBLE
2661 2662
Case #11: IMPOSSIBLE
108 109
Case #12: 1
1117 1118
Case #13: IMPOSSIBLE
358 359
Cas...

result:

wrong answer 1st lines differ - expected: 'Case #1: 114', found: '623 624'