結果
問題 | No.2042 RGB Caps |
ユーザー | mkawa2 |
提出日時 | 2023-03-01 22:08:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 532 ms / 2,000 ms |
コード長 | 1,629 bytes |
コンパイル時間 | 325 ms |
コンパイル使用メモリ | 87,148 KB |
実行使用メモリ | 113,464 KB |
最終ジャッジ日時 | 2023-10-15 01:42:55 |
合計ジャッジ時間 | 6,775 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
71,564 KB |
testcase_01 | AC | 77 ms
71,368 KB |
testcase_02 | AC | 77 ms
71,316 KB |
testcase_03 | AC | 78 ms
71,516 KB |
testcase_04 | AC | 78 ms
71,328 KB |
testcase_05 | AC | 78 ms
71,400 KB |
testcase_06 | AC | 170 ms
86,600 KB |
testcase_07 | AC | 232 ms
91,336 KB |
testcase_08 | AC | 368 ms
102,604 KB |
testcase_09 | AC | 147 ms
81,788 KB |
testcase_10 | AC | 488 ms
111,512 KB |
testcase_11 | AC | 143 ms
86,424 KB |
testcase_12 | AC | 532 ms
113,256 KB |
testcase_13 | AC | 532 ms
113,464 KB |
testcase_14 | AC | 528 ms
113,408 KB |
testcase_15 | AC | 78 ms
71,368 KB |
testcase_16 | AC | 210 ms
89,892 KB |
testcase_17 | AC | 134 ms
81,096 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 # md = 10**9+7 md = 998244353 s = "RGB" n, k = LI() color = [set() for _ in range(n)] nxt = [-1]*n ac = [] for _ in range(k): a, c = SI().split() a = int(a)-1 c = s.find(c) color[a].add(c) nxt[a] = c ac.append((a, c)) for i in range(n-1)[::-1]: color[i] |= color[i+1] if nxt[i] == -1: nxt[i] = nxt[i+1] # print(color) # print(nxt) aa = [-1]*n cnt = [0, 0, 0] for i in range(n): nc = nxt[i] if cnt[nc] != max(cnt): aa[i] = nc else: mnc, mn = 0, inf for c in color[i]: if cnt[c] < mn: mn, mnc = cnt[c], c if mn == cnt[nc]: aa[i] = nc else: aa[i] = mnc cnt[aa[i]] += 1 ac.sort(reverse=True) cnt = [0, 0, 0] for i, a in enumerate(aa): cnt[a] += 1 if ac and ac[-1][0] == i: _, c = ac.pop() if cnt[c] != max(cnt): print(-1) exit() print("".join(s[i] for i in aa))