結果
| 問題 | No.3374 Caesar Shift Game |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-11-22 05:41:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,071 bytes |
| 記録 | |
| コンパイル時間 | 397 ms |
| コンパイル使用メモリ | 82,644 KB |
| 実行使用メモリ | 113,128 KB |
| 最終ジャッジ日時 | 2025-11-22 05:41:15 |
| 合計ジャッジ時間 | 5,386 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 1 |
| other | AC * 10 RE * 25 |
ソースコード
from collections import deque
import sys
sys.setrecursionlimit(10**6)
def find_abc(cs: list):
a = deque()
b = deque()
c = deque()
for i, x in enumerate(cs):
if x == 'A':
a.append(i)
elif x == 'B':
b.append(i)
elif x == 'C':
c.append(i)
return a, b, c
def f(cs: list, a, b, c):
ai = a.popleft() if a else INF
bi = b.popleft() if b else INF
ci = c.popleft() if c else INF
if ci < ai and ci < bi:
cs[c] = 'A'
return g(cs, a, b, c)
return cs
def g(cs: list, a, b, c):
ai = a.popleft() if a else INF
bi = b.popleft() if b else INF
ci = c.popleft() if c else INF
if ci < ai and ci < bi:
return cs
if a < b:
cs[a] = 'B'
elif b < INF:
cs[b] = 'C'
return f(cs, a, b, c)
def solve():
N = int(input())
S = input()
cs = list(S)
a, b, c = find_abc(cs)
res = f(cs, a, b, c)
return ''.join(res)
INF = 1 << 60
T = int(input())
for _ in range(T):
ans = solve()
print(ans)
norioc