結果
問題 | No.517 壊れたアクセサリー |
ユーザー |
![]() |
提出日時 | 2018-07-18 22:48:44 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 691 bytes |
コンパイル時間 | 94 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-12-16 10:23:46 |
合計ジャッジ時間 | 1,286 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
word_list = [[],[]]initial = []head_w = []word_length = 0for i in range(int(input())):word = input()word_list[0].append(word)initial.append(word[0])word_length += len(word)for i in range(int(input())):word = input()word_list[1].append(word)if word[0] in initial:head_w.append(word[0])if len(head_w)!=1:print(-1)else:ans = head_w[0]choise_flag = 0while len(ans)!=word_length:tgt = ans[-1]for i,w in enumerate(word_list[choise_flag]):if tgt in w:ans += w[w.index(tgt)+1:]word_list[choise_flag].pop(i)choise_flag = (choise_flag+1)%2print(ans)