結果
問題 |
No.517 壊れたアクセサリー
|
ユーザー |
![]() |
提出日時 | 2021-11-05 04:59:30 |
言語 | Ruby (3.4.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 973 bytes |
コンパイル時間 | 93 ms |
コンパイル使用メモリ | 7,680 KB |
実行使用メモリ | 19,108 KB |
最終ジャッジ日時 | 2024-10-15 12:21:08 |
合計ジャッジ時間 | 5,867 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 13 TLE * 1 -- * 1 |
コンパイルメッセージ
Main.rb:68: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
N = gets.to_i A = N.times.map { gets.chomp } M = gets.to_i B = M.times.map { gets.chomp } S = A.map(&:size).sum E1 = Hash.new { |h, k| h[k] = [] } ANS = [] N.times do |i| a1 = A[i].chars a1.each_cons(2) do |c1, c2| E1[c1] << c2 end N.times do |j| next if i == j a2 = A[j].chars E1[a1.last] << a2.first end end E2 = Hash.new { |h, k| h[k] = [] } M.times do |i| b1 = B[i].chars b1.each_cons(2) do |c1, c2| E2[c1] << c2 end M.times do |j| next if i == j b2 = B[j].chars E2[b1.last] << b2.first end end def dfs(c, str, visited) visited[c] = true if str.size == S ANS << str return end E1[c].each do |nc| next if visited[nc] next if not E2[c].include?(nc) dfs(nc, str + nc, visited) end visited[c] = false end B.each do |b| next if not A.find { |a| a[0] == b[0] } visited = Hash.new(false) dfs(b[0], b[0], visited) end if ANS.size == 1 puts ANS.first else puts -1 end