結果

問題 No.157 2つの空洞
ユーザー gigurururugigurururu
提出日時 2015-02-26 23:49:35
言語 Ruby
(3.2.2)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 507 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 11,112 KB
実行使用メモリ 15,348 KB
最終ジャッジ日時 2023-09-06 02:53:16
合計ジャッジ時間 2,625 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,036 KB
testcase_01 AC 80 ms
15,124 KB
testcase_02 AC 79 ms
15,120 KB
testcase_03 AC 80 ms
15,176 KB
testcase_04 AC 80 ms
15,340 KB
testcase_05 AC 80 ms
15,120 KB
testcase_06 AC 82 ms
15,296 KB
testcase_07 AC 80 ms
15,292 KB
testcase_08 AC 80 ms
15,048 KB
testcase_09 AC 79 ms
15,032 KB
testcase_10 AC 79 ms
15,120 KB
testcase_11 AC 80 ms
15,252 KB
testcase_12 AC 81 ms
15,160 KB
testcase_13 AC 81 ms
15,240 KB
testcase_14 AC 81 ms
15,348 KB
testcase_15 AC 81 ms
15,004 KB
testcase_16 AC 80 ms
15,284 KB
testcase_17 AC 80 ms
15,116 KB
testcase_18 AC 80 ms
15,140 KB
testcase_19 AC 79 ms
15,132 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]==?.}}
q=[[fx,fy,0]]
c[fy][fx]=?+
n=0
while q[n]
  x,y=q[n]
  [[x+1,y],[x-1,y],[x,y+1],[x,y-1]].each{|tx,ty|
    if c[ty][tx]==?.
      q<<[tx,ty,0]
      c[ty][tx]=?+
    end
  }
  n+=1
end
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[ty][tx]
    when ?.
      p i
      exit
    when ?#
      q<<[tx,ty,i+1]
      c[ty][tx]=?+
    end
  }
end
0