結果
| 問題 | 
                            No.517 壊れたアクセサリー
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2017-05-29 23:58:16 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 89 ms / 2,000 ms | 
| コード長 | 601 bytes | 
| コンパイル時間 | 44 ms | 
| コンパイル使用メモリ | 7,296 KB | 
| 実行使用メモリ | 12,288 KB | 
| 最終ジャッジ日時 | 2024-09-21 18:15:38 | 
| 合計ジャッジ時間 | 2,300 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 15 | 
コンパイルメッセージ
Main.rb:33: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
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