QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#49878#3829. Stephen Cookckiseki#AC ✓2630ms11520kbPython3956b2022-09-23 19:09:592022-09-23 19:10:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-23 19:10:02]
  • 评测
  • 测评结果:AC
  • 用时:2630ms
  • 内存:11520kb
  • [2022-09-23 19:09:59]
  • 提交

answer

def evaluate(s, o):
    o2 = ''
    for c in o:
        if ord('A') <= ord(c) <= ord('Z'):
            idx = ord(c) - ord('A')
            o2 += str(bool((s >> idx) & 1))
        else:
            o2 += c
    return eval(o2)

def solve(n, o):
    n2 = 1 << n
    dp = [{} for _ in range(n2)]
    for s in range(n2):
        dp[n2 - 1][s] = evaluate(s, o)

    for s in range(n2 - 2, -1, -1):
        turn = bin(s).count('1') & 1
        msk = s
        while True:
            dp[s][msk] = turn
            for i in range(n):
                if ((s >> i) & 1) == 0:
                    if dp[s | (1 << i)][msk] != turn or dp[s | (1 << i)][msk | (1 << i)] != turn:
                        dp[s][msk] = 1 - turn
                        break
            if msk == 0:
                break
            msk = (msk - 1) & s
    print("Cook" if dp[0][0] else "Levin")

t = int(input())
for kase in range(t):
    n = int(input())
    s = input()
    solve(n, s)


詳細信息

Test #1:

score: 100
Accepted
time: 2630ms
memory: 11520kb

input:

20
9
( not not not not E or ( F and ( ( C or E ) and not ( E and not not G ) ) or not ( not not ( A and B and D ) and not not A or not I ) ) ) and ( ( not ( C and ( ( E or E ) and not I ) ) or not H ) and not H )
7
not ( ( F or not ( not C or not G and not F ) ) and ( C or E or ( not not not C and A...

output:

Cook
Cook
Levin
Cook
Cook
Cook
Cook
Cook
Levin
Cook
Levin
Levin
Levin
Levin
Levin
Levin
Levin
Levin
Levin
Cook

result:

ok 20 lines