結果

問題 No.2042 RGB Caps
ユーザー shotoyooshotoyoo
提出日時 2022-08-20 01:05:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 111,056 KB
最終ジャッジ日時 2024-04-27 20:36:54
合計ジャッジ時間 3,178 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,144 KB
testcase_01 AC 37 ms
54,400 KB
testcase_02 AC 38 ms
54,272 KB
testcase_03 AC 38 ms
54,144 KB
testcase_04 AC 38 ms
54,656 KB
testcase_05 AC 38 ms
54,400 KB
testcase_06 AC 91 ms
85,620 KB
testcase_07 AC 134 ms
88,392 KB
testcase_08 AC 193 ms
100,408 KB
testcase_09 AC 103 ms
79,616 KB
testcase_10 AC 235 ms
106,268 KB
testcase_11 AC 98 ms
80,736 KB
testcase_12 AC 251 ms
111,056 KB
testcase_13 AC 258 ms
110,880 KB
testcase_14 AC 251 ms
110,920 KB
testcase_15 AC 42 ms
54,784 KB
testcase_16 AC 142 ms
87,296 KB
testcase_17 AC 101 ms
78,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, random
input = lambda : sys.stdin.readline().rstrip()


write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18
LI = lambda : list(map(int, input().split())); II=lambda : int(input())
def debug(_l_):
    for s in _l_.split():
        print(f"{s}={eval(s)}", end=" ")
    print()
def dlist(*l, fill=0):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [dlist(*ll, fill=fill) for _ in range(l[0])]

n,k = list(map(int, input().split()))
ans = [0]*(n+3)
tmp = [[] for _ in range(n+3)]
vals = {}
ac = [input() for _ in range(k)]
ac.sort()
for i in range(k):
    a,c = ac[i].split()
    a = int(a)
    a -= 1
    vals[a] = c
    d,m = divmod(a,3)
    for ind in range(3*d, 3*d+3):
        if c in tmp[ind]:
            break
    else:
        ans[a] = c
        for ind in range(3*d, 3*d+3):
            tmp[ind].append(c)
#     print(tmp, c)
for i in range((n+2)//3):
    s = set("RGB")
    for j in range(3*i, 3*i+3):
        if ans[j]!=0:
            s.remove(ans[j])
    for j in range(3*i, 3*i+3):
        if ans[j]==0:
            ans[j] = s.pop()
count = {}
for c in "RGB":
    count[c] = 0
for i in range(n):
    assert ans[i] in "RGB"
    count[ans[i]] += 1
    if i in vals:
        assert count[vals[i]]==max(count.values())
write("".join(ans[:n]))
0