Submission #12745157


Source Code Expand

Copy
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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)
    print('\n'.join(answer))
except Exception:
    print('No')

Submission Info

Submission Time
Task F - Three Variables Game
User maspy
Language Python (3.8.2)
Score 600
Code Size 1654 Byte
Status
Exec Time 76 ms
Memory 15912 KB

Test Cases

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