結果
| 問題 |
No.3234 Infinite Propagation
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-08-15 22:50:12 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 211 ms / 2,000 ms |
| コード長 | 677 bytes |
| コンパイル時間 | 205 ms |
| コンパイル使用メモリ | 82,112 KB |
| 実行使用メモリ | 92,704 KB |
| 最終ジャッジ日時 | 2025-08-15 22:51:19 |
| 合計ジャッジ時間 | 2,810 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
import sys
sys.setrecursionlimit(10 ** 6)
def dfs(s: str, used, items):
for i, (x, y) in enumerate(items):
p = s.find(x)
if p == -1: continue
if used[i]:
return True
used[i] = True
t = s[:p] + y + s[p+len(x):]
if dfs(t, used, items):
return True
used[i] = False
return False
def solve():
N = int(input())
items = []
for _ in range(N):
X, Y = input().split()
items.append((X, Y))
used = [False] * N
return dfs('a', used, items)
T = int(input())
for _ in range(T):
ans = solve()
if ans:
print('Yes')
else:
print('No')
norioc