結果

問題 No.517 壊れたアクセサリー
ユーザー mitsuomitsuo
提出日時 2017-06-20 17:19:54
言語 Python2
(2.7.18)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 05:49:43
合計ジャッジ時間 1,115 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

def solve(input):
    chain = {}
    s = set([])

    for w in input:
        if w.isdigit() :
            continue

        for i in xrange(len(w)) :
            s.add(w[i])
            if i + 1 < len(w) :
                chain[w[i]] = w[i + 1]

    if len(s) == 1 :
        return s.pop()

    if len(s) - 1 > len(chain) :
        return "-1"

    k = set(chain.keys())
    v = set(chain.values())

    first = ((k ^ v) & k).pop()
    end = ((k ^ v) & v).pop()

    i = first
    r = first

    while i != end :
        r += chain[i]
        i = chain[i]

    return r
    pass

if __name__ == "__main__":
    input = []
    ln = int(raw_input())
    input.append(str(ln))
    for l in xrange(ln):
        input.append(raw_input())

    ln = int(raw_input())
    input.append(str(ln))
    for l in xrange(ln):
        input.append(raw_input())

    print solve(input)
0