結果

問題 No.517 壊れたアクセサリー
ユーザー maimai
提出日時 2017-05-28 21:48:04
言語 Ruby
(3.3.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 11,872 KB
実行使用メモリ 16,052 KB
最終ジャッジ日時 2023-10-21 14:07:54
合計ジャッジ時間 2,621 ms
ジャッジサーバーID
(参考情報)
judge14 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
16,052 KB
testcase_01 AC 95 ms
16,052 KB
testcase_02 AC 93 ms
16,052 KB
testcase_03 AC 90 ms
16,052 KB
testcase_04 AC 87 ms
16,052 KB
testcase_05 AC 91 ms
16,052 KB
testcase_06 AC 91 ms
16,052 KB
testcase_07 AC 90 ms
16,052 KB
testcase_08 AC 88 ms
16,052 KB
testcase_09 AC 88 ms
16,052 KB
testcase_10 AC 87 ms
16,052 KB
testcase_11 AC 87 ms
16,052 KB
testcase_12 AC 90 ms
16,052 KB
testcase_13 AC 89 ms
16,052 KB
testcase_14 AC 88 ms
16,052 KB
testcase_15 AC 88 ms
16,052 KB
testcase_16 AC 88 ms
16,052 KB
testcase_17 AC 90 ms
16,052 KB
testcase_18 AC 89 ms
16,052 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def scan; gets.split.map(&:to_i); end

def sayno
    puts "-1";exit
end

#u = ['I','II','III','IV','V','VI','VII']

ac = {}
z = {}
gets.to_i.times{
    s = gets.chomp
    s.chars{|c| z[c]=0}
    (s.size-1).times{|i|
        ac[s[i]] = s[i+1]
        z[s[i+1]] = 1
    }
}
gets.to_i.times{
    s = gets.chomp
    # s.chars{|c| z[c]=0}
    (s.size-1).times{|i|
        sayno if ac[s[i]] && ac[s[i]] != s[i+1]
        ac[s[i]] = s[i+1]
        z[s[i+1]] = 1
    }
}

start = nil
z.each{|k,v|
    if v==0
        sayno if start
        start = k
    end
}
sayno if !start

str = start
while ac[start]
    start = ac[start]
    str+=start
end

sayno if z.size != str.size

puts str

0