結果

問題 No.517 壊れたアクセサリー
ユーザー kohei2019
提出日時 2022-02-05 18:12:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 52,352 KB
最終ジャッジ日時 2024-06-11 13:37:34
合計ジャッジ時間 1,784 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
lsA = [input() for i in range(N)]
M = int(input())
lsB = [input() for i in range(M)]
nextls = dict()
Np = 0
for i in range(N):
    s = lsA[i]
    n = len(lsA[i])
    Np += n
    for j in range(n-1):
        nextls[s[j]] = s[j+1]

for i in range(M):
    s = lsB[i]
    m = len(lsB[i])
    for j in range(m-1):
        nextls[s[j]] = s[j+1]

if Np==1:
    print(lsA[0])
    exit()

for key in nextls.keys():
    now = key
    moji = key
    while now in nextls:
        moji += nextls[now]
        now = nextls[now]
    if len(moji) == Np:
        print(moji)
        exit()
print('-1')

0