結果

問題 No.517 壊れたアクセサリー
ユーザー 👑 rin204rin204
提出日時 2022-07-10 15:23:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 71,588 KB
最終ジャッジ日時 2023-09-01 21:43:13
合計ジャッジ時間 3,517 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,096 KB
testcase_01 AC 74 ms
71,040 KB
testcase_02 AC 72 ms
71,288 KB
testcase_03 AC 73 ms
71,388 KB
testcase_04 AC 73 ms
71,420 KB
testcase_05 AC 72 ms
71,340 KB
testcase_06 AC 73 ms
71,292 KB
testcase_07 AC 72 ms
71,448 KB
testcase_08 AC 73 ms
71,344 KB
testcase_09 AC 72 ms
71,284 KB
testcase_10 AC 72 ms
71,588 KB
testcase_11 AC 72 ms
71,416 KB
testcase_12 AC 73 ms
71,228 KB
testcase_13 AC 72 ms
71,428 KB
testcase_14 AC 73 ms
71,260 KB
testcase_15 AC 72 ms
71,388 KB
testcase_16 AC 73 ms
71,232 KB
testcase_17 AC 74 ms
71,152 KB
testcase_18 AC 72 ms
71,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

se = set()
n = int(input())
edges = [set() for _ in range(26)]
in_ = [0] * 26
for _ in range(n):
    S = input()
    for s in S:
        se.add(ord(s) - 65)
    for i in range(len(S) - 1):
        p1 = ord(S[i]) - 65
        p2 = ord(S[i + 1]) - 65
        edges[p1].add(p2)
        in_[p2] += 1
n = int(input())
for _ in range(n):
    S = input()
    for i in range(len(S) - 1):
        p1 = ord(S[i]) - 65
        p2 = ord(S[i + 1]) - 65
        edges[p1].add(p2)
        in_[p2] += 1

for i in range(26):
    if in_[i] == 0 and i in se:
        s = i
        break

used = [False] * 26
ans = [chr(65 + s)]
used[s] = True
while 1:
    if len(edges[s]) >= 2:
        print(-1)
        exit()
    elif len(edges[s]) == 0:
        break
    for t in edges[s]:
        break
    if used[t]:
        print(-1)
        exit()
    s = t
    used[s] = True
    ans.append(chr(s + 65))

if len(se) == used.count(True):
    print(*ans, sep="")
else:
    print(-1)
0