結果

問題 No.2042 RGB Caps
ユーザー FromBooskaFromBooska
提出日時 2023-03-21 22:48:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,334 bytes
コンパイル時間 1,087 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 108,352 KB
最終ジャッジ日時 2023-10-18 18:38:30
合計ジャッジ時間 9,202 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,500 KB
testcase_01 WA -
testcase_02 AC 38 ms
53,500 KB
testcase_03 AC 40 ms
53,500 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

N, K = map(int, input().split())
dic = {}
M = 0
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
    M = max(M, int(a))

RGB = [0, 0, 0]
ans = ''
for i in range(1, M+1):
    if i in dic:
        RGB[dic[i]] += 1
        ans += 'RGB'[dic[i]]
    elif i+1 in dic:
        avoid = dic[i+1]
        mn = min(RGB)
        mn_list = []
        for j in range(3):
            if RGB[j] == mn:
                mn_list.append(j)
        if len(mn_list) == 1:
            RGB[j] += 1
            ans += 'RGB'[j]
        else:
            for j in mn_list:
                if j != avoid:
                    RGB[j] += 1
                    ans += 'RGB'[j]
                    break
    else:
        mn = min(RGB)
        for j in range(3):
            if RGB[j] == mn:
                RGB[j] += 1
                ans += 'RGB'[j]
                break
print(ans)



0