QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#49876#3829. Stephen Cookckiseki#TL 0ms0kbPython31.1kb2022-09-23 18:46:192022-09-23 18:46:22

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 18:46:22]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2022-09-23 18:46:19]
  • 提交

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(1024)]
    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):
                    if turn == 0:
                        dp[s][msk] = max(dp[s][msk], dp[s | (1 << i)][msk])
                        dp[s][msk] = max(dp[s][msk], dp[s | (1 << i)][msk | (1 << i)])
                    else:
                        dp[s][msk] = min(dp[s][msk], dp[s | (1 << i)][msk])
                        dp[s][msk] = min(dp[s][msk], dp[s | (1 << i)][msk | (1 << i)])
            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)


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

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

result: