結果

問題 No.483 マッチ並べ
ユーザー smz_8110smz_8110
提出日時 2017-04-13 17:13:10
言語 Ruby
(3.3.0)
結果
AC  
実行時間 850 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 57 ms
コンパイル使用メモリ 11,628 KB
実行使用メモリ 15,500 KB
最終ジャッジ日時 2023-09-25 16:25:50
合計ジャッジ時間 9,456 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,104 KB
testcase_01 AC 82 ms
15,180 KB
testcase_02 AC 81 ms
15,080 KB
testcase_03 AC 80 ms
15,300 KB
testcase_04 AC 80 ms
15,152 KB
testcase_05 AC 81 ms
15,092 KB
testcase_06 AC 85 ms
15,084 KB
testcase_07 AC 82 ms
15,244 KB
testcase_08 AC 82 ms
15,128 KB
testcase_09 AC 79 ms
15,156 KB
testcase_10 AC 82 ms
15,088 KB
testcase_11 AC 79 ms
15,084 KB
testcase_12 AC 79 ms
15,092 KB
testcase_13 AC 79 ms
15,088 KB
testcase_14 AC 80 ms
15,176 KB
testcase_15 AC 84 ms
15,256 KB
testcase_16 AC 81 ms
15,296 KB
testcase_17 AC 82 ms
15,156 KB
testcase_18 AC 78 ms
15,328 KB
testcase_19 AC 118 ms
15,252 KB
testcase_20 AC 79 ms
15,356 KB
testcase_21 AC 79 ms
15,128 KB
testcase_22 AC 80 ms
15,168 KB
testcase_23 AC 81 ms
15,148 KB
testcase_24 AC 81 ms
15,088 KB
testcase_25 AC 98 ms
15,244 KB
testcase_26 AC 90 ms
15,104 KB
testcase_27 AC 90 ms
15,104 KB
testcase_28 AC 81 ms
15,080 KB
testcase_29 AC 81 ms
15,224 KB
testcase_30 AC 81 ms
15,056 KB
testcase_31 AC 81 ms
15,280 KB
testcase_32 AC 84 ms
15,100 KB
testcase_33 AC 88 ms
15,156 KB
testcase_34 AC 81 ms
15,108 KB
testcase_35 AC 85 ms
15,148 KB
testcase_36 AC 83 ms
15,152 KB
testcase_37 AC 84 ms
15,232 KB
testcase_38 AC 95 ms
15,336 KB
testcase_39 AC 82 ms
15,296 KB
testcase_40 AC 82 ms
15,124 KB
testcase_41 AC 89 ms
15,252 KB
testcase_42 AC 84 ms
15,176 KB
testcase_43 AC 86 ms
15,128 KB
testcase_44 AC 95 ms
15,328 KB
testcase_45 AC 86 ms
15,184 KB
testcase_46 AC 83 ms
15,104 KB
testcase_47 AC 134 ms
15,232 KB
testcase_48 AC 850 ms
15,364 KB
testcase_49 AC 468 ms
15,268 KB
testcase_50 AC 305 ms
15,356 KB
testcase_51 AC 82 ms
15,160 KB
testcase_52 AC 142 ms
15,500 KB
testcase_53 AC 80 ms
15,056 KB
testcase_54 AC 80 ms
15,208 KB
testcase_55 AC 83 ms
15,180 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{
  return true if o[a]
  u[a]=true
  o[a]=true
  b=h[a[4]]
  c=h[a[5]]
  if b.size==1
    if c.size==1
      return true
    else
      z=true
      c.each{|d|
        z&&=F[m,h,d,r,o,u]
      }
      o[a]=false
      return z
    end
  elsif c.size==1
    z=true
    b.each{|d|
      z&&=F[m,h,d,r,o,u]
    }
    o[a]=false
    return z
  else
    unless r[a[0]][a[1]]
      r[a[0]][a[1]]=true
      z=true
      c.each{|d|
        z&&=F[m,h,d,r,o,u]
      }
      b.each{|d|
        z&&=F[m,h,d,r,o,u]
      }
      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
      c.each{|d|
        z&&=F[m,h,d,r,o,u]
      }
      b.each{|d|
        z&&=F[m,h,d,r,o,u]
      }
      r[a[2]][a[3]]=false
      o[a]=false
      return z
    end
  end
  o[a]=false
  false
}
u={}
m.each{|a|
  next if u[a]
  r=112.times.map{[]}
  unless F[m,h,a,r,{},u]
    puts "NO"
    exit
  end
}
puts "YES"
0