結果
| 問題 |
No.2042 RGB Caps
|
| コンテスト | |
| ユーザー |
wattaihei
|
| 提出日時 | 2022-08-19 21:50:01 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 814 bytes |
| コンパイル時間 | 217 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 93,568 KB |
| 最終ジャッジ日時 | 2024-10-08 08:16:01 |
| 合計ジャッジ時間 | 5,766 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 3 WA * 13 |
ソースコード
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))
wattaihei