結果

問題 No.517 壊れたアクセサリー
ユーザー convexineqconvexineq
提出日時 2021-02-18 10:38:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 420 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 71,512 KB
最終ジャッジ日時 2023-10-12 19:21:47
合計ジャッジ時間 2,884 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,232 KB
testcase_01 AC 71 ms
71,400 KB
testcase_02 AC 71 ms
71,116 KB
testcase_03 AC 71 ms
71,284 KB
testcase_04 AC 70 ms
71,256 KB
testcase_05 AC 71 ms
71,288 KB
testcase_06 AC 70 ms
71,512 KB
testcase_07 AC 72 ms
71,232 KB
testcase_08 AC 72 ms
71,300 KB
testcase_09 AC 71 ms
71,320 KB
testcase_10 AC 71 ms
71,480 KB
testcase_11 AC 72 ms
71,204 KB
testcase_12 AC 71 ms
71,364 KB
testcase_13 AC 72 ms
71,112 KB
testcase_14 AC 71 ms
71,432 KB
testcase_15 AC 71 ms
71,404 KB
testcase_16 AC 73 ms
71,332 KB
testcase_17 AC 72 ms
71,276 KB
testcase_18 AC 72 ms
71,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
ds = set(si[0] for si in s)
dt = set(ti[0] for ti in t)
if len(ds&dt)>1:
    print(-1)
else:
    g = {}
    for si in s+t:
        for p,q in zip(si,si[1:]):
            g[p] = q
    ans = []
    v = list(ds&dt)[0]
    while True:
        ans.append(v)
        if v not in g: break
        v = g[v]
    print("".join(ans))
0