結果

問題 No.13 囲みたい!
ユーザー gigurururugigurururu
提出日時 2014-11-27 21:54:34
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 381 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 11,496 KB
実行使用メモリ 54,496 KB
最終ジャッジ日時 2023-09-01 22:20:51
合計ジャッジ時間 4,309 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,092 KB
testcase_01 AC 81 ms
15,040 KB
testcase_02 AC 79 ms
15,084 KB
testcase_03 RE -
testcase_04 AC 88 ms
15,676 KB
testcase_05 RE -
testcase_06 AC 143 ms
19,488 KB
testcase_07 AC 178 ms
18,596 KB
testcase_08 AC 140 ms
16,704 KB
testcase_09 AC 141 ms
16,572 KB
testcase_10 AC 90 ms
15,188 KB
testcase_11 AC 127 ms
16,020 KB
testcase_12 AC 87 ms
15,180 KB
testcase_13 AC 99 ms
15,432 KB
testcase_14 AC 101 ms
15,692 KB
testcase_15 AC 82 ms
15,132 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def g;gets.split.map(&:to_i);end
w,h=g
$m=(1..h).map{g+[0]}+[0]*w

$checked={}

def dfs(gone,dir,x,y,c)
  r=[[0,-1],[1,0],[-1,0],[0,1]]
  $m[y][x]==c&&($checked[[x,y]]=true;gone.index([x,y])||(0..3).any?{|i|i!=dir&&dfs(gone+[[x,y]],3-i,x+r[i][0],y+r[i][1],c)})
end

puts (0...h).any?{|y|(0...w).any?{|x|!$checked[[x,y]]&&dfs([],-1,x,y,$m[y][x])}}?"possible":"impossible"
0