結果

問題 No.517 壊れたアクセサリー
ユーザー magurogumamaguroguma
提出日時 2017-08-04 21:17:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,702 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-20 02:05:45
合計ジャッジ時間 1,408 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# -*- coding: utf-8 -*-

class Stone:
    def __init__(self, left, right):
        self.left = left
        self.right = right

N = int(input())
A = [''] * N
for i in range(N):
    A[i] = input()
M = int(input())
B = [''] * M
for i in range(M):
    B[i] = input()

stone_dict = {}

#はじめに全文字の追加
for i in range(N):
    segment = A[i]
    for character in segment:
        stone = Stone('','')
        stone_dict[character] = stone

#結城君の断片のチェック
for i in range(N):
    segment = A[i]
    for j in range(len(segment)):
        me = segment[j]
        left = ''
        right = ''
        if j-1 >= 0:
            left = segment[j-1]
        if j+1 < len(segment):
            right = segment[j+1]
        stone_dict[me].left = left
        stone_dict[me].right = right

#幸田さんの断片のチェック
for i in range(M):
    segment = B[i]
    for j in range(len(segment)):
        me = segment[j]
        left = stone_dict[me].left
        right = stone_dict[me].right
        if j-1 >= 0:
            left = segment[j-1]
        if j+1 < len(segment):
            right = segment[j+1]
        stone_dict[me].left = left
        stone_dict[me].right = right

'''
for key in stone_dict:
    print('me:' + key + ',left:' + stone_dict[key].left + ',right:' + stone_dict[key].right)
'''

output_string = ''
for key in stone_dict:
    if stone_dict[key].left == '':
        output_string += key
        nc = stone_dict[key].right
        while len(output_string)<len(stone_dict) and nc!='':
            output_string += nc
            nc = stone_dict[nc].right
        break

if len(output_string) == len(stone_dict):
    print(output_string)
else:
    print(-1)
0