結果

問題 No.483 マッチ並べ
ユーザー smz_8110smz_8110
提出日時 2017-04-14 09:35:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 11,432 KB
実行使用メモリ 15,424 KB
最終ジャッジ日時 2023-09-25 19:13:43
合計ジャッジ時間 7,769 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,296 KB
testcase_01 AC 79 ms
15,048 KB
testcase_02 AC 78 ms
15,068 KB
testcase_03 AC 79 ms
15,156 KB
testcase_04 AC 78 ms
15,104 KB
testcase_05 AC 78 ms
15,132 KB
testcase_06 AC 79 ms
15,296 KB
testcase_07 AC 79 ms
15,236 KB
testcase_08 AC 79 ms
15,112 KB
testcase_09 AC 77 ms
15,148 KB
testcase_10 AC 80 ms
15,116 KB
testcase_11 AC 79 ms
15,088 KB
testcase_12 AC 79 ms
15,284 KB
testcase_13 AC 79 ms
15,136 KB
testcase_14 AC 78 ms
15,336 KB
testcase_15 AC 77 ms
15,044 KB
testcase_16 AC 78 ms
15,216 KB
testcase_17 AC 77 ms
15,084 KB
testcase_18 AC 77 ms
15,152 KB
testcase_19 AC 78 ms
15,048 KB
testcase_20 AC 78 ms
15,216 KB
testcase_21 AC 78 ms
15,336 KB
testcase_22 AC 78 ms
15,068 KB
testcase_23 AC 78 ms
15,288 KB
testcase_24 AC 78 ms
15,184 KB
testcase_25 AC 79 ms
15,272 KB
testcase_26 AC 82 ms
15,264 KB
testcase_27 AC 81 ms
15,244 KB
testcase_28 AC 81 ms
15,048 KB
testcase_29 AC 83 ms
15,136 KB
testcase_30 AC 82 ms
15,032 KB
testcase_31 AC 81 ms
15,116 KB
testcase_32 AC 80 ms
15,240 KB
testcase_33 AC 79 ms
15,264 KB
testcase_34 AC 79 ms
15,280 KB
testcase_35 AC 81 ms
15,068 KB
testcase_36 AC 81 ms
15,128 KB
testcase_37 AC 82 ms
15,260 KB
testcase_38 AC 82 ms
15,232 KB
testcase_39 AC 79 ms
15,084 KB
testcase_40 AC 79 ms
15,084 KB
testcase_41 AC 81 ms
15,136 KB
testcase_42 AC 80 ms
15,080 KB
testcase_43 AC 84 ms
15,236 KB
testcase_44 AC 80 ms
15,188 KB
testcase_45 AC 82 ms
15,340 KB
testcase_46 AC 79 ms
15,132 KB
testcase_47 AC 87 ms
15,184 KB
testcase_48 AC 103 ms
15,424 KB
testcase_49 AC 86 ms
15,160 KB
testcase_50 AC 87 ms
15,160 KB
testcase_51 AC 84 ms
15,132 KB
testcase_52 AC 86 ms
15,276 KB
testcase_53 AC 79 ms
15,064 KB
testcase_54 AC 79 ms
15,044 KB
testcase_55 AC 79 ms
15,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N=gets.to_i
h={}
m=N.times.map{
  a=gets.split.map(&:to_i)
  a<<(b=a[0]*1000+a[1])
  a<<(c=a[2]*1000+a[3])
  (h[b]=(h[b]||[]))<<a
  (h[c]=(h[c]||[]))<<a
  a
}
F=->m,h,a,r,o,u{
  u[a]=true
  o[a]=true
  b=h[a[4]]
  c=h[a[5]]
  g=b|c
  if b.size==1
    if c.size==1
      return true
    else
      z=true
      c.each{|d|
        unless o[d]
          z=F[m,h,d,r,o,u]
          break unless z
        end
      }
      o[a]=false
      return z
    end
  elsif c.size==1
    z=true
    b.each{|d|
      unless o[d]
        z=F[m,h,d,r,o,u] 
        break unless z
      end
    }
    o[a]=false
    return z
  else
    unless r[a[0]][a[1]]
      r[a[0]][a[1]]=true
      z=true
      g.each{|d|
        unless o[d]
          z=F[m,h,d,r,o,u] 
          break unless z
        end
      }
      r[a[0]][a[1]]=false
      if z
        o[a]=false
        return true
      end
    end
    unless r[a[2]][a[3]]
      r[a[2]][a[3]]=true
      z=true
      g.each{|d|
        unless o[d]
          z=F[m,h,d,r,o,u] 
          break unless z
        end
      }
      r[a[2]][a[3]]=false
      o[a]=false
      return z
    end
  end
  o[a]=false
  false
}

u={}
m.each{|a|u[a]=true if h[a[4]].size==1||h[a[5]].size==1}
m.each{|a|
  next if u[a]
  r=112.times.map{[]}
  unless F[m,h,a,r,{}.merge(u),u]
    puts "NO"
    exit
  end
}
puts "YES"
0