QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#49878 | #3829. Stephen Cook | ckiseki# | AC ✓ | 2630ms | 11520kb | Python3 | 956b | 2022-09-23 19:09:59 | 2022-09-23 19:10:02 |
Judging History
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