結果

問題 No.2042 RGB Caps
ユーザー asumo0729asumo0729
提出日時 2022-08-19 22:47:57
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,509 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 84,776 KB
最終ジャッジ日時 2024-04-17 01:25:16
合計ジャッジ時間 5,860 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 TLE -
testcase_17 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from operator import itemgetter, le
from collections import defaultdict, deque
import heapq
from heapq import heapify, heappop, _heapify_max, heappush
from bisect import bisect_left, bisect_right
import math
import itertools
import copy

stdin=sys.stdin
#sys.setrecursionlimit(10 ** 7)
## import pypyjit
## pypyjit.set_param('max_unroll_recursion=-1')

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
Yp=lambda:print('Yes')
Np=lambda:print('No')
inf = 1 << 60
mod = 10 ** 9 + 7
mod = 998244353
eps = 1e-9
sortkey1 = itemgetter(0)
sortkey2 = lambda x: (x[0], x[1])



###############################################################

N, K = lp()
A = []
col = [-1 for _ in range(N)]
RGB = 'RGB'
for _ in range(K):
    a, c = input().split()
    a = int(a) - 1;c = RGB.index(c)
    col[a] = c
    A.append((a,c))
A.sort(reverse=True)

rgb = [0 for _ in range(3)]
idx = N
ans = [-1 for _ in range(N)]
for i in range(N - 1, - 1, -1):
    if col[i] == -1:
        if ans[i] != -1:
            rgb[ans[i]] -= 1
        continue
    c = col[i]
    need = (i + 1) // 3 + 1
    r = min(i, idx) + 1
    if need - rgb[c] > r:
        print(-1)
        exit()
    t = 0
    use = need - rgb[c]
    for j in range(r, -1, -1):
        if t == use:
            break
        ans[r] = c
        rgb[c] += 1
        t += 1
        r -= 1
    #print(ans)
answer = []
for x in ans:
    answer.append(RGB[x])
print(''.join(answer))


    
0