結果

問題 No.517 壊れたアクセサリー
ユーザー kimiyukikimiyuki
提出日時 2017-05-28 21:35:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 11,900 KB
実行使用メモリ 10,116 KB
最終ジャッジ日時 2023-10-21 14:04:47
合計ジャッジ時間 1,624 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#!/usr/bin/env python3
import string

def find_startswith(c, xs):
    for x in xs:
        if x.startswith(c):
            return x
def find_roots(xs, ys):
    for c in string.ascii_uppercase:
        if find_startswith(c, xs) and find_startswith(c, ys):
            yield c

def solve(xs, ys):
    n = len(''.join(xs))
    roots = list(find_roots(xs, ys))
    if len(roots) != 1:
        return -1
    root, = roots
    a = find_startswith(root, xs)
    b = find_startswith(root, ys)
    while len(a) < n or len(b) < n:
        if len(a) < len(b):
            c = b[len(a) :][0]
            d = find_startswith(c, xs)
            if not d:
                return -1
            a += d
        elif len(b) < len(a):
            c = a[len(b) :][0]
            d = find_startswith(c, ys)
            if not d:
                return -1
            b += d
        else:
            return -1
    assert a == b
    return a

n = int(input())
xs = [ input() for _ in range(n) ]
m = int(input())
ys = [ input() for _ in range(m) ]
print(solve(xs, ys))
0