QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#49876 | #3829. Stephen Cook | ckiseki# | TL | 0ms | 0kb | Python3 | 1.1kb | 2022-09-23 18:46:19 | 2022-09-23 18:46:22 |
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(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