結果

問題 No.2629 A replace B replace C
コンテスト
ユーザー NP
提出日時 2024-02-16 22:11:29
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 841 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 248 ms
コンパイル使用メモリ 95,812 KB
実行使用メモリ 1,335,552 KB
最終ジャッジ日時 2026-09-05 18:03:35
合計ジャッジ時間 4,140 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 5
other AC * 1 MLE * 2 -- * 58
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque

def solve(N, S, T):
    queue = deque([(S, 0)])
    visited = {S}

    while queue:
        current, step = queue.popleft()
        if current == T:
            return 'Yes'
        if step == N:
            continue
        for i in range(N):
            if current[i] == 'A':
                next_state = current[:i] + 'B' + current[i+1:]
                if next_state not in visited:
                    visited.add(next_state)
                    queue.append((next_state, step+1))
            elif current[i] == 'B':
                next_state = current[:i] + 'C' + current[i+1:]
                if next_state not in visited:
                    visited.add(next_state)
                    queue.append((next_state, step+1))
    return 'No'

N = int(input())
S = input()
T = input()
print(solve(N, S, T))
0