結果

問題 No.517 壊れたアクセサリー
ユーザー nebukuro09nebukuro09
提出日時 2017-05-28 21:33:44
言語 Python2
(2.7.18)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 7,104 KB
実行使用メモリ 6,504 KB
最終ジャッジ日時 2023-10-21 14:03:59
合計ジャッジ時間 1,382 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,500 KB
testcase_01 AC 9 ms
6,500 KB
testcase_02 AC 9 ms
6,500 KB
testcase_03 AC 9 ms
6,500 KB
testcase_04 AC 10 ms
6,500 KB
testcase_05 AC 9 ms
6,500 KB
testcase_06 AC 9 ms
6,500 KB
testcase_07 AC 10 ms
6,500 KB
testcase_08 AC 10 ms
6,500 KB
testcase_09 AC 10 ms
6,500 KB
testcase_10 AC 10 ms
6,500 KB
testcase_11 AC 9 ms
6,500 KB
testcase_12 AC 10 ms
6,500 KB
testcase_13 AC 10 ms
6,500 KB
testcase_14 AC 10 ms
6,500 KB
testcase_15 AC 9 ms
6,500 KB
testcase_16 AC 9 ms
6,500 KB
testcase_17 AC 10 ms
6,504 KB
testcase_18 AC 9 ms
6,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = input()
A = [raw_input() for _ in xrange(N)]
M = input()
B = [raw_input() for _ in xrange(M)]

if N == 1:
    print A[0]
    exit()
if M == 1:
    print B[0]
    exit()

first = set([a[0] for a in A]) & set([b[0] for b in B])
if len(first) > 1:
    print -1
    exit()
last = first.pop()
ans = last

while len(A) > 0 or len(B) > 0:
    for i in xrange(len(A)):
        if last in A[i]:
            j = A[i].find(last)
            ans += A[i][j+1:]
            last = A[i][-1]
            A.pop(i)
            break
        if A[i] in ans:
            A.pop(i)
            break
    for i in xrange(len(B)):
        if last in B[i]:
            j = B[i].find(last)
            ans += B[i][j+1:]
            last = B[i][-1]
            B.pop(i)
            break
        if B[i] in ans:
            B.pop(i)
            break

print ans
0