結果

問題 No.157 2つの空洞
ユーザー gigurururugigurururu
提出日時 2015-02-26 23:44:24
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 534 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 11,444 KB
実行使用メモリ 15,296 KB
最終ジャッジ日時 2023-09-06 02:50:05
合計ジャッジ時間 3,462 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,296 KB
testcase_01 AC 79 ms
15,268 KB
testcase_02 AC 78 ms
15,296 KB
testcase_03 AC 78 ms
15,112 KB
testcase_04 AC 79 ms
15,132 KB
testcase_05 AC 83 ms
15,172 KB
testcase_06 AC 82 ms
15,132 KB
testcase_07 AC 81 ms
15,088 KB
testcase_08 AC 80 ms
15,256 KB
testcase_09 AC 79 ms
15,212 KB
testcase_10 AC 80 ms
15,256 KB
testcase_11 AC 78 ms
15,172 KB
testcase_12 RE -
testcase_13 WA -
testcase_14 AC 78 ms
15,108 KB
testcase_15 AC 78 ms
15,080 KB
testcase_16 AC 78 ms
15,000 KB
testcase_17 AC 78 ms
15,256 KB
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def g;gets.split.map(&:to_i)end
w,h=g
c=(0...h).map{gets+?+}+[?+*w]
fx=fy=0
fy=(0...h).find{|i|fx=(0...w).find{|j|c[i][j]==?.}}
qf=[[fx,fy]]
c[fx][fy]=?+
n=0
while qf[n]
  x,y=qf[n]
  [[x+1,y],[x-1,y],[x,y+1],[x,y-1]].each{|tx,ty|
    if c[tx][ty]==?.
      qf<<[tx,ty]
      c[tx][ty]=?+
    end
  }
  n+=1
end
q=qf.map{|tx,ty|[tx,ty,0]}
while q[0]
  x,y,i=q.shift
  [[x+1,y],[x-1,y],[x,y+1],[x,y-1]].each{|tx,ty|
    case c[tx][ty]
    when ?.
      p i
      exit
    when ?#
      q<<[tx,ty,i+1]
      c[tx][ty]=?+
    end
  }
end
0