結果

問題 No.2042 RGB Caps
ユーザー FromBooskaFromBooska
提出日時 2023-03-22 11:36:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 756 ms / 2,000 ms
コード長 1,108 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 81,812 KB
実行使用メモリ 108,716 KB
最終ジャッジ日時 2023-10-18 18:56:16
合計ジャッジ時間 7,569 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,544 KB
testcase_01 AC 38 ms
53,544 KB
testcase_02 AC 37 ms
53,544 KB
testcase_03 AC 37 ms
53,544 KB
testcase_04 AC 38 ms
53,544 KB
testcase_05 AC 37 ms
53,544 KB
testcase_06 AC 663 ms
103,180 KB
testcase_07 AC 193 ms
79,712 KB
testcase_08 AC 462 ms
90,260 KB
testcase_09 AC 100 ms
77,300 KB
testcase_10 AC 718 ms
106,172 KB
testcase_11 AC 136 ms
76,944 KB
testcase_12 AC 742 ms
108,716 KB
testcase_13 AC 751 ms
108,624 KB
testcase_14 AC 756 ms
108,644 KB
testcase_15 AC 39 ms
53,544 KB
testcase_16 AC 170 ms
79,296 KB
testcase_17 AC 93 ms
76,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# DFSは動いていたが、MLEとなった、まあそうだろうね
# 逆順で最低値で行けばいいのでは
# 入力例1なら at 5, [?, ?, 2]. at 3, [?, 1, ?], at 1 [1, 0, 0]
# つなぐのがうまくいかない
# 解説より
# 前からできるだけイーブンにしていく、そうすれば次のものに対応できる

N, K = map(int, input().split())
dic = {}
for i in range(K):
    a, c = map(str, input().split())
    if c == 'R':
        dic[int(a)] = 0
    elif c == 'G':
        dic[int(a)] = 1
    elif c == 'B':
        dic[int(a)] = 2

#print(dic)

RGB = [0, 0, 0]
ans = ''
for i in range(1, N+1):
    if i in dic:
        if RGB[dic[i]] == min(RGB):
            RGB[dic[i]] += 1
            ans += 'RGB'[dic[i]]
            #print(i, 'dic[i]', dic[i])
        else:
            mn_idx = RGB.index(min(RGB))
            RGB[mn_idx] += 1
            ans += 'RGB'[mn_idx]
            #print(i, 'mn_idx', mn_idx)
    else:
        mn_idx = RGB.index(min(RGB))
        RGB[mn_idx] += 1
        ans += 'RGB'[mn_idx]
        #print(i, 'mn_idx', mn_idx)
    #print(ans)
print(ans)
0