結果
問題 | No.517 壊れたアクセサリー |
ユーザー |
![]() |
提出日時 | 2021-11-05 05:17:06 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 1,062 bytes |
コンパイル時間 | 346 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,160 KB |
最終ジャッジ日時 | 2024-10-15 12:44:19 |
合計ジャッジ時間 | 3,028 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
コンパイルメッセージ
Main.rb:70: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
N = gets.to_iA = N.times.map { gets.chomp }M = gets.to_iB = M.times.map { gets.chomp }S = A.map(&:size).sumE1 = Hash.new { |h, k| h[k] = Hash.new(false) }ANS = []N.times do |i|a1 = A[i].charsa1.each_cons(2) do |c1, c2|E1[c1][c2] = trueendN.times do |j|next if i == ja2 = A[j].charsE1[a1.last][a2.first] = trueendendE2 = Hash.new { |h, k| h[k] = Hash.new(false) }M.times do |i|b1 = B[i].charsb1.each_cons(2) do |c1, c2|E2[c1][c2] = trueendM.times do |j|next if i == jb2 = B[j].charsE2[b1.last][b2.first] = trueendenddef dfs(c, str, visited)return if ANS.size >= 2visited[c] = trueif str.size == SANS << strvisited[c] = falsereturnendE1[c].each do |nc, _|next if visited[nc]next if not E2[c][nc]dfs(nc, str + nc, visited)endvisited[c] = falseendA.each do |a|next if not B.find { |b| a[0] == b[0] }visited = Hash.new(false)dfs(a[0], a[0], visited)endif ANS.size == 1puts ANS.firstelseputs -1end