結果

問題 No.3374 Caesar Shift Game
コンテスト
ユーザー norioc
提出日時 2025-11-22 05:26:33
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 945 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 609 ms
コンパイル使用メモリ 82,748 KB
実行使用メモリ 103,756 KB
最終ジャッジ日時 2025-11-22 05:26:39
合計ジャッジ時間 5,595 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 WA * 1 RE * 3 TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def find_abc(cs: list, used: set):
    a = b = c = INF
    for i, x in enumerate(cs):
        if x == 'A':
            if i not in used:
                a = min(a, i)
        elif x == 'B':
            if i not in used:
                b = min(b, i)
        elif x == 'C':
            if i not in used:
                c = min(c, i)

    return a, b, c


def f(cs: list, used: set):
    a, b, c = find_abc(cs, used)
    if c < a and c < b:
        cs[c] = 'A'
        used.add(c)
        return g(cs, used)

    return cs


def g(cs: list, used: set):
    a, b, c = find_abc(cs, used)
    if c < a and c < b:
        return cs

    if a < b:
        cs[a] = 'B'
        used.add(a)
    else:
        cs[b] = 'C'
        used.add(b)

    return f(cs, used)


def solve():
    N = int(input())
    S = input()
    res = f(list(S), set())
    return ''.join(res)


INF = 1 << 60
T = int(input())
for _ in range(T):
    ans = solve()
    print(ans)
0