結果

問題 No.2042 RGB Caps
ユーザー ntudantuda
提出日時 2022-08-23 21:02:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 685 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 89,972 KB
最終ジャッジ日時 2024-04-19 11:46:33
合計ジャッジ時間 3,707 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,348 KB
testcase_01 AC 34 ms
53,148 KB
testcase_02 AC 31 ms
53,424 KB
testcase_03 AC 33 ms
52,396 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 35 ms
54,924 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 #

N, K = map(int, input().split())
AC = []
for _ in range(K):
    a, c = input().split()
    AC.append((int(a), c))
AC.sort()
ans = []
dic = {"R": 0, "G": 1, "B": 2}
color = ["R", "G", "B"]
X = [0, 0, 0]
used = 0
for a, c in AC:
    unused = a - used
    i = dic[c]
    xnow = X[i]
    xmax = max(X)
    xdif = xmax - xnow
    if unused < xdif:
        print(-1)
        exit()
    else:
        X[i] += xdif
        ans += [c] * xdif
        unused -= xdif
        used += xdif
    Y = X[0:]
    Y.sort()
    x2nd = Y[1]
    xdif2 = xmax - x2nd
    xadd = - ((- unused + xdif2) // 2)
    X[i] += xadd
    ans += [c] * xadd
    used += xadd
ans += ["R"] * (N - used)
print("".join(ans))
0