結果
| 問題 |
No.517 壊れたアクセサリー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-28 21:35:58 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 1,046 bytes |
| コンパイル時間 | 160 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-09-21 15:18:40 |
| 合計ジャッジ時間 | 1,596 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
#!/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))