結果
問題 | No.517 壊れたアクセサリー |
ユーザー |
![]() |
提出日時 | 2020-02-26 16:10:49 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 795 bytes |
コンパイル時間 | 84 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-10-13 15:24:11 |
合計ジャッジ時間 | 1,447 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
#!/usr/bin/env python3# %%import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlines# %%N = int(readline())A = [readline().decode().rstrip() for _ in range(N)]M = int(readline())B = [readline().decode().rstrip() for _ in range(M)]# %%E = dict()V = set()for word in A + B:V |= set(word)for x, y in zip(word, word[1:]):E[x] = y# %%def solve(V, E):start = V - set(E.values())if len(start) != 1:return Nonex = start.pop()chain = [x]while True:if x not in E:breakx = E[x]chain.append(x)if len(chain) < len(V):return Nonereturn ''.join(chain)# %%S = solve(V,E)if not S:print(-1)else:print(S)# %%