結果

問題 No.2042 RGB Caps
ユーザー roarisroaris
提出日時 2022-08-20 02:25:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 83,476 KB
最終ジャッジ日時 2024-04-27 20:36:50
合計ジャッジ時間 2,835 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,224 KB
testcase_01 AC 33 ms
52,224 KB
testcase_02 AC 34 ms
51,840 KB
testcase_03 AC 39 ms
52,224 KB
testcase_04 AC 34 ms
52,480 KB
testcase_05 AC 33 ms
52,352 KB
testcase_06 AC 80 ms
80,492 KB
testcase_07 AC 140 ms
78,468 KB
testcase_08 AC 147 ms
81,276 KB
testcase_09 AC 103 ms
76,816 KB
testcase_10 AC 178 ms
83,416 KB
testcase_11 AC 91 ms
78,056 KB
testcase_12 AC 175 ms
83,476 KB
testcase_13 AC 180 ms
83,028 KB
testcase_14 AC 191 ms
83,016 KB
testcase_15 AC 38 ms
59,512 KB
testcase_16 AC 118 ms
77,784 KB
testcase_17 AC 104 ms
76,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def f1(s):
    if s=='R':
        return 0
    elif s=='G':
        return 1
    else:
        return 2

def f2(x):
    if x==0:
        return 'R'
    elif x==1:
        return 'G'
    else:
        return 'B'

N, K = map(int, input().split())
color = [-1]*(N+1)

for _ in range(K):
    A, c = input().split()
    color[int(A)] = f1(c)

cnt = [0, 0, 0]
ans = []

for i in range(1, N+1):
    if color[i]==-1:
        m = min(cnt)
        i = cnt.index(m)
        cnt[i] += 1
        ans.append(i)
    else:
        d = 5
        x = -1

        for j in range(3):
            cnt[j] += 1
            M = max(cnt)
            m = min(cnt)
        
            if color[i] in [k for k in range(3) if cnt[k]==M]:
                if d>M-m:
                    d = M-m
                    x = j
                
            cnt[j] -= 1
        
        assert(x!=-1)
        cnt[x] += 1
        ans.append(x)

cnt = [0, 0, 0]

for i in range(1, N+1):
    cnt[ans[i-1]] += 1
    M = max(cnt)
    
    if color[i]!=-1:
        assert(color[i] in [k for k in range(3) if cnt[k]==M])

print(''.join(map(f2, ans)))
0