結果

問題 No.2042 RGB Caps
ユーザー wattaiheiwattaihei
提出日時 2022-08-19 21:50:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 93,676 KB
最終ジャッジ日時 2024-04-17 00:31:21
合計ジャッジ時間 6,494 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
51,968 KB
testcase_01 WA -
testcase_02 AC 38 ms
51,840 KB
testcase_03 AC 39 ms
52,224 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 62 ms
75,776 KB
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 #

import sys
input = sys.stdin.readline

N, K = map(int, input().rstrip().split())
A = []
for _ in range(K):
    a = list(map(str, input().rstrip().split()))
    A.append((int(a[0]), a[1]))
A.sort()

S = [0, 0, 0]
ans = []
for sa, c in A:
    a = int(sa)
    u = "RGB".index(c)
    now = S[u]
    others_max = max(S[(u+1)%3], S[(u-1)%3])
    su = sum(S)
    more = max(max((a+2)//3, others_max) - now, 0)
    if su + more <= a:
        S[u] += more
        for _ in range(more):
            ans.append(c)
    else:
        S = []
        break

if not S:
    print(-1)
else:
    while len(ans) < N:
        tmp = 10**18
        ind = -1
        for i in range(3):
            if S[i] < tmp:
                tmp = S[i]
                ind = i
        S[ind] += 1
        ans.append("RGB"[ind])
    print("".join(ans))
0