結果
| 問題 | No.2629 A replace B replace C |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-16 22:11:29 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 841 bytes |
| 記録 | |
| コンパイル時間 | 274 ms |
| コンパイル使用メモリ | 82,216 KB |
| 実行使用メモリ | 848,408 KB |
| 最終ジャッジ日時 | 2024-09-28 20:27:53 |
| 合計ジャッジ時間 | 2,727 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 5 |
| other | AC * 1 MLE * 1 -- * 59 |
ソースコード
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))