結果

問題 No.517 壊れたアクセサリー
ユーザー cympfhcympfh
提出日時 2017-05-29 23:58:16
言語 Ruby
(3.3.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 11,940 KB
実行使用メモリ 16,124 KB
最終ジャッジ日時 2023-10-21 17:01:10
合計ジャッジ時間 2,923 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
16,124 KB
testcase_01 AC 88 ms
16,124 KB
testcase_02 AC 86 ms
16,124 KB
testcase_03 AC 88 ms
16,124 KB
testcase_04 AC 86 ms
16,124 KB
testcase_05 AC 87 ms
16,124 KB
testcase_06 AC 87 ms
16,124 KB
testcase_07 AC 84 ms
16,124 KB
testcase_08 AC 84 ms
16,124 KB
testcase_09 AC 84 ms
16,124 KB
testcase_10 AC 84 ms
16,124 KB
testcase_11 AC 83 ms
16,124 KB
testcase_12 AC 84 ms
16,124 KB
testcase_13 AC 89 ms
16,124 KB
testcase_14 AC 85 ms
16,124 KB
testcase_15 AC 83 ms
16,124 KB
testcase_16 AC 84 ms
16,124 KB
testcase_17 AC 84 ms
16,124 KB
testcase_18 AC 88 ms
16,124 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:33: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

m = gets.to_i
as = (1..m).map { gets.chomp }
n = gets.to_i
bs = (1..n).map { gets.chomp }

adic = {}
bdic = {}
as.each { |a| adic[a[0]] = a }
bs.each { |b| bdic[b[0]] = b }

('A'..'Z').each do |head|
  next unless adic[head]
  next unless bdic[head]
  abuf = adic[head]
  bbuf = bdic[head]

  aused = 1

  while abuf.size != bbuf.size
    if abuf.size > bbuf.size
      head = abuf[bbuf.size]
      bbuf += bdic[head]
    else
      head = bbuf[abuf.size]
      abuf += adic[head]
      aused += 1
    end
  end

  next if abuf != bbuf

  if aused < m
    p -1
    break
  end

  puts abuf
  break
end
0