結果

問題 No.2042 RGB Caps
ユーザー ntudantuda
提出日時 2022-08-23 21:07:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 751 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 21,624 KB
最終ジャッジ日時 2024-04-19 11:49:47
合計ジャッジ時間 3,041 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 25 ms
10,752 KB
testcase_03 AC 25 ms
10,752 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 30 ms
12,544 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
    if unused < xdif2:
        continue
    else:
        xadd = - ((- unused + xdif2) // 2)
        X[i] += xadd
        ans += [c] * xadd
        used += xadd
ans += ["R"] * (N - used)
print("".join(ans))
0