結果
問題 | No.2042 RGB Caps |
ユーザー | tamato |
提出日時 | 2022-08-19 21:42:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 139 ms / 2,000 ms |
コード長 | 2,419 bytes |
コンパイル時間 | 137 ms |
コンパイル使用メモリ | 82,092 KB |
実行使用メモリ | 81,164 KB |
最終ジャッジ日時 | 2024-11-16 01:54:25 |
合計ジャッジ時間 | 2,468 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 |
ソースコード
mod = 998244353 def main(): import sys input = sys.stdin.readline T = {"R": 0, "G": 1, "B": 2} N, K = map(int, input().split()) ans = [""] * (N + 10) for _ in range(K): a, c = input().split() a = int(a) ans[a-1] = c for i in range((N // 3) + 1): cnt = [0] * 3 for j in range(3): s = ans[i * 3 + j] if s == "R": cnt[0] += 1 elif s == "G": cnt[1] += 1 elif s == "B": cnt[2] += 1 # j = 0 if ans[i * 3] == "": if cnt[0] == 0: ans[i * 3] = "R" cnt[0] += 1 elif cnt[1] == 0: ans[i * 3] = "G" cnt[1] += 1 else: ans[i * 3] = "B" cnt[2] += 1 # j = 1 if ans[i * 3 + 1] == "": if cnt[0] == 0: ans[i * 3 + 1] = "R" cnt[0] += 1 elif cnt[1] == 0: ans[i * 3 + 1] = "G" cnt[1] += 1 else: ans[i * 3 + 1] = "B" cnt[2] += 1 else: s = ans[i * 3 + 1] if cnt[T[s]] > 1 and ans[i * 3 + 1] == ans[i * 3]: cnt[T[s]] -= 1 if cnt[0] == 0: ans[i * 3 + 1] = "R" cnt[0] += 1 elif cnt[1] == 0: ans[i * 3 + 1] = "G" cnt[1] += 1 else: ans[i * 3 + 1] = "B" cnt[2] += 1 # j = 2 if ans[i * 3 + 2] == "": if cnt[0] == 0: ans[i * 3 + 2] = "R" cnt[0] += 1 elif cnt[1] == 0: ans[i * 3 + 2] = "G" cnt[1] += 1 else: ans[i * 3 + 2] = "B" cnt[2] += 1 else: s = ans[i * 3 + 2] if cnt[T[s]] > 1: cnt[T[s]] -= 1 if cnt[0] == 0: ans[i * 3 + 2] = "R" cnt[0] += 1 elif cnt[1] == 0: ans[i * 3 + 2] = "G" cnt[1] += 1 else: ans[i * 3 + 2] = "B" cnt[2] += 1 print("".join(ans[:N])) if __name__ == '__main__': main()