結果

問題 No.659 徘徊迷路
ユーザー letrangerjpletrangerjp
提出日時 2018-03-03 19:40:16
言語 Ruby
(3.3.0)
結果
AC  
実行時間 403 ms / 2,000 ms
コード長 653 bytes
コンパイル時間 46 ms
コンパイル使用メモリ 11,208 KB
実行使用メモリ 15,484 KB
最終ジャッジ日時 2023-09-17 05:00:12
合計ジャッジ時間 4,994 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
15,304 KB
testcase_01 AC 93 ms
15,248 KB
testcase_02 AC 96 ms
15,156 KB
testcase_03 AC 91 ms
15,208 KB
testcase_04 AC 201 ms
15,352 KB
testcase_05 AC 78 ms
15,132 KB
testcase_06 AC 72 ms
15,152 KB
testcase_07 AC 70 ms
15,296 KB
testcase_08 AC 105 ms
15,420 KB
testcase_09 AC 250 ms
15,424 KB
testcase_10 AC 311 ms
15,400 KB
testcase_11 AC 403 ms
15,392 KB
testcase_12 AC 69 ms
15,024 KB
testcase_13 AC 392 ms
15,308 KB
testcase_14 AC 403 ms
15,428 KB
testcase_15 AC 399 ms
15,428 KB
testcase_16 AC 390 ms
15,484 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

R, C, T = gets.split.map &:to_i
Sy, Sx = gets.split.map &:to_i
Gy, Gx = gets.split.map &:to_i
Board = $<.map{|s|s.chomp.chars}
dirs = R.times.map{|y|
  C.times.map{|x|
    [1,0,-1,0,1].each_cons(2).select{|dy,dx|
      Board.fetch(y+dy,[])[x+dx] != ?#
    }
  }
}


dp = R.times.map{[0.0]*C}
dp[Sy][Sx] = 1.0
[T, 5000+T%2].min.times{
  next_dp = R.times.map{ [0.0]*C }
  R.times{|y|
    C.times{|x|
      next if Board[y][x] == ?#
      d = dirs[y][x]
      if d.empty?
        next_dp[y][x] += dp[y][x]
        next
      end
      d.each{|(dy, dx)|
        next_dp[y+dy][x+dx] += dp[y][x] / d.size
      }
    }
  }
  dp = next_dp
}
p dp[Gy][Gx].to_f
0