結果

問題 No.2042 RGB Caps
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-08-19 22:14:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 522 ms / 2,000 ms
コード長 995 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 100,772 KB
最終ジャッジ日時 2024-04-27 20:34:20
合計ジャッジ時間 4,723 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,228 KB
testcase_01 AC 41 ms
53,148 KB
testcase_02 AC 38 ms
53,696 KB
testcase_03 AC 37 ms
53,128 KB
testcase_04 AC 38 ms
52,280 KB
testcase_05 AC 38 ms
52,672 KB
testcase_06 AC 104 ms
80,324 KB
testcase_07 AC 208 ms
84,072 KB
testcase_08 AC 348 ms
93,396 KB
testcase_09 AC 141 ms
79,396 KB
testcase_10 AC 486 ms
99,196 KB
testcase_11 AC 127 ms
78,560 KB
testcase_12 AC 516 ms
99,664 KB
testcase_13 AC 521 ms
100,772 KB
testcase_14 AC 522 ms
100,400 KB
testcase_15 AC 42 ms
59,284 KB
testcase_16 AC 190 ms
82,552 KB
testcase_17 AC 122 ms
78,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from cmath import inf


n,k = map(int,input().split())
ans = []
RGB = [0]*3

AC = []
for i in range(k):
    a,c = input().split()
    a = int(a)
    AC.append([a,c])
AC.sort()
l = "RGB"
now = 0
for i in range(1,n+1):
    
    target = 0
    ind = -1
    if now < k and AC[now][0] == i:
        c = AC[now][1]
        ind = l.index(c)

        if max(RGB) == RGB[ind]:
            if RGB.count(max(RGB)) == 3:
                target = ind
            else:
                for j in range(3):
                    if RGB[j] != max(RGB):
                        target = j
                        break

        else:
            target = ind


        now += 1
    else:
        for j in range(3):
            if RGB[j] != max(RGB):
                target = j
                break
    
    ans.append(target)
    RGB[target] += 1

    assert max(RGB)-min(RGB) <= 1

    if ind != -1 and max(RGB) != RGB[ind]:
        print(-1)
        exit()
        
ans = [l[i] for i in ans]
print("".join(ans))
0