結果

問題 No.2629 A replace B replace C
コンテスト
ユーザー NP
提出日時 2024-02-16 22:11:29
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 841 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,264 ms
コンパイル使用メモリ 85,328 KB
実行使用メモリ 1,336,888 KB
最終ジャッジ日時 2026-04-15 09:11:46
合計ジャッジ時間 3,819 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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