Contest Duration: - (local time) (100 minutes) Back to Home

Submission #12745157

Source Code Expand

Copy
```import sys

Q, A, B, C = map(int, readline().split())
N = A + B + C

S = tuple(0 if s == b'BC' else 1 if s == b'AC' else 2 for s in S)

def solve_1(N, A, B, C, S):
nums = [A, B, C]
for s in S:
if nums[s] == N:
raise Exception
i, j = (0, 1) if s == 2 else (0, 2) if s == 1 else (1, 2)
if nums[i] < nums[j]:
i, j = j, i
yield j
nums[j] += 1
nums[i] -= 1

def solve_2(N, A, B, C, S):
nums = [A, B, C]
s = S[0]
# 初手で死亡
if nums[s] == N:
raise Exception
# あとはできる。きわどいときは 2 手読み
S = S + (0, )
for s, t in zip(S, S[1:]):
i, j = (0, 1) if s == 2 else (0, 2) if s == 1 else (1, 2)
if (nums[i], nums[j]) != (1, 1):
if nums[i] < nums[j]:
i, j = j, i
elif s != t:
i, j = t, 3 - s - t
yield j
nums[j] += 1
nums[i] -= 1

def large(N, A, B, C, S):
nums = [A, B, C]
for s in S:
if nums[s] == N:
raise Exception
i, j = (0, 1) if s == 2 else (0, 2) if s == 1 else (1, 2)
if nums[i] < nums[j]:
i, j = j, i
yield j
nums[j] += 1
nums[i] -= 1

f = solve_1 if N == 1 else solve_2 if N == 2 else large

try:
cmds = list(f(N, A, B, C, S))
print('Yes')
answer = ('ABC' [i] for i in cmds)
except Exception:
print('No')

```

Submission Info

Submission Time 2020-05-03 21:41:46+0900 F - Three Variables Game maspy Python (3.8.2) 600 1654 Byte AC 76 ms 15912 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
 AC × 4
 AC × 60
Set Name Test Cases
Sample Sample_01.txt, Sample_02.txt, Sample_03.txt, Sample_04.txt
All Sample_01.txt, Sample_02.txt, Sample_03.txt, Sample_04.txt, killer_01.txt, killer_02.txt, killer_03.txt, killer_04.txt, killer_05.txt, killer_06.txt, killer_07.txt, killer_08.txt, killer_09.txt, killer_10.txt, one_alive01.txt, one_alive02.txt, one_alive03.txt, one_alive04.txt, one_death01.txt, one_death02.txt, one_death03.txt, one_death04.txt, prime_alive01.txt, prime_alive02.txt, prime_alive03.txt, prime_alive04.txt, prime_alive05.txt, prime_death01.txt, prime_death02.txt, prime_death03.txt, prime_death04.txt, prime_death05.txt, prime_death06.txt, prime_death07.txt, prime_death08.txt, prime_death09.txt, prime_death10.txt, superkiller_01.txt, superkiller_02.txt, superkiller_03.txt, superkiller_04.txt, superkiller_05.txt, superkiller_06.txt, superkiller_07.txt, superkiller_08.txt, superkiller_09.txt, superkiller_10.txt, three_01.txt, three_02.txt, three_03.txt, three_04.txt, two_01.txt, two_02.txt, two_03.txt, two_04.txt, two_05.txt, two_06.txt, two_07.txt, two_08.txt, zero_01.txt
Case Name Status Exec Time Memory
Sample_01.txt AC 19 ms 9108 KB
Sample_02.txt AC 21 ms 9344 KB
Sample_03.txt AC 19 ms 9264 KB
Sample_04.txt AC 24 ms 9400 KB
killer_01.txt AC 74 ms 15592 KB
killer_02.txt AC 75 ms 15752 KB
killer_03.txt AC 75 ms 15912 KB
killer_04.txt AC 74 ms 15776 KB
killer_05.txt AC 73 ms 15832 KB
killer_06.txt AC 35 ms 15764 KB
killer_07.txt AC 76 ms 15804 KB
killer_08.txt AC 75 ms 15836 KB
killer_09.txt AC 76 ms 15912 KB
killer_10.txt AC 75 ms 15596 KB
one_alive01.txt AC 20 ms 9212 KB
one_alive02.txt AC 22 ms 9272 KB
one_alive03.txt AC 70 ms 15776 KB
one_alive04.txt AC 71 ms 15604 KB
one_death01.txt AC 19 ms 9404 KB
one_death02.txt AC 25 ms 9216 KB
one_death03.txt AC 39 ms 15708 KB
one_death04.txt AC 35 ms 15600 KB
prime_alive01.txt AC 24 ms 9160 KB
prime_alive02.txt AC 18 ms 9112 KB
prime_alive03.txt AC 66 ms 15696 KB
prime_alive04.txt AC 71 ms 15772 KB
prime_alive05.txt AC 71 ms 15596 KB
prime_death01.txt AC 20 ms 9212 KB
prime_death02.txt AC 21 ms 9220 KB
prime_death03.txt AC 51 ms 14968 KB
prime_death04.txt AC 36 ms 12716 KB
prime_death05.txt AC 47 ms 14868 KB
prime_death06.txt AC 41 ms 13960 KB
prime_death07.txt AC 50 ms 14740 KB
prime_death08.txt AC 46 ms 13620 KB
prime_death09.txt AC 36 ms 12456 KB
prime_death10.txt AC 44 ms 13560 KB
superkiller_01.txt AC 67 ms 15596 KB
superkiller_02.txt AC 68 ms 15596 KB
superkiller_03.txt AC 72 ms 15768 KB
superkiller_04.txt AC 66 ms 15700 KB
superkiller_05.txt AC 68 ms 15772 KB
superkiller_06.txt AC 69 ms 15596 KB
superkiller_07.txt AC 68 ms 15596 KB
superkiller_08.txt AC 68 ms 15776 KB
superkiller_09.txt AC 73 ms 15912 KB
superkiller_10.txt AC 69 ms 15704 KB
three_01.txt AC 20 ms 9168 KB
three_02.txt AC 23 ms 9280 KB
three_03.txt AC 75 ms 15728 KB
three_04.txt AC 73 ms 15764 KB
two_01.txt AC 20 ms 9116 KB
two_02.txt AC 24 ms 9344 KB
two_03.txt AC 19 ms 9112 KB
two_04.txt AC 22 ms 9208 KB
two_05.txt AC 27 ms 9272 KB
two_06.txt AC 68 ms 15908 KB
two_07.txt AC 71 ms 15912 KB
two_08.txt AC 69 ms 15768 KB
zero_01.txt AC 34 ms 15592 KB