結果
問題 | No.517 壊れたアクセサリー |
ユーザー |
![]() |
提出日時 | 2017-05-28 21:58:33 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 1,711 bytes |
コンパイル時間 | 93 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-09-21 15:25:32 |
合計ジャッジ時間 | 1,682 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
# coding: utf-8import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, timesys.setrecursionlimit(10 ** 7)INF = 10 ** 20MOD = 10 ** 9 + 7def II(): return int(input())def ILI(): return list(map(int, input().split()))def IAI(LINE): return [ILI() for __ in range(LINE)]def IDI(): return {key: value for key, value in ILI()}def read():N = II()A = []for __ in range(N):A.append(str(input()))M = II()B = []for __ in range(M):B.append(str(input()))return (N, A, M, B)def solve(N, A, M, B):dict_next = collections.defaultdict(None)all_len = 0for a in A:all_len += len(a)for char_a in a:dict_next[char_a] = Nonedef update_dict(str_list):for str in str_list:for i in range(len(str) - 1):dict_next[str[i]] = str[i + 1]update_dict(A)update_dict(B)count_none = 0for value in dict_next.values():if value is None:count_none += 1ans = ""if count_none != 1:ans = -1else:l_ans = []now_char = ""for key, value in dict_next.items():if value is None:now_char = keyl_ans.append(now_char)while len(l_ans) != all_len:for key, value in dict_next.items():if value is now_char:l_ans.append(key)now_char = keybreakelse:l_ans.reverse()ans = "".join(l_ans)return ansdef main():params = read()print(solve(*params))if __name__ == "__main__":main()