結果
問題 | No.13 囲みたい! |
ユーザー | letrangerjp |
提出日時 | 2017-05-20 16:16:06 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 137 ms / 5,000 ms |
コード長 | 848 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 11,932 KB |
実行使用メモリ | 17,848 KB |
最終ジャッジ日時 | 2023-10-19 04:12:09 |
合計ジャッジ時間 | 3,003 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 89 ms
16,108 KB |
testcase_01 | AC | 87 ms
16,108 KB |
testcase_02 | AC | 87 ms
16,108 KB |
testcase_03 | AC | 99 ms
17,240 KB |
testcase_04 | AC | 93 ms
16,428 KB |
testcase_05 | AC | 137 ms
17,848 KB |
testcase_06 | AC | 94 ms
16,428 KB |
testcase_07 | AC | 132 ms
17,352 KB |
testcase_08 | AC | 131 ms
17,376 KB |
testcase_09 | AC | 130 ms
17,380 KB |
testcase_10 | AC | 94 ms
16,308 KB |
testcase_11 | AC | 117 ms
16,892 KB |
testcase_12 | AC | 92 ms
16,108 KB |
testcase_13 | AC | 102 ms
16,528 KB |
testcase_14 | AC | 103 ms
16,448 KB |
testcase_15 | AC | 89 ms
16,108 KB |
コンパイルメッセージ
Syntax OK
ソースコード
def f(board, width, height) visited = {} g = lambda{|h, w, n=board[h][w], cnt=0, from=nil| return if !h.between?(0, height-1) return if !w.between?(0, width-1) return if n != board[h][w] # p [n, cnt, [h,w]] return !from.nil? if visited[[h,w]] cnt += 1 visited[[h,w]] = true from != :l && g.(h, w-1, n, cnt, :r) || from != :r && g.(h, w+1, n, cnt, :l) || from != :u && g.(h-1, w, n, cnt, :d) || from != :d && g.(h+1, w, n, cnt, :u) } # visited.each{|l| puts l.join} height.times{|h| width.times{|w| if g.(h, w) # p [h,w] # visited.each{|l| puts l.join} return true end } } # visited.each{|l| puts l.join} false end W, H = gets.split.take(2).map(&:to_i) M = H.times.map{gets.split.take(W).map(&:to_i)} puts f(M, W, H) ? :possible : :impossible