結果
問題 | No.659 徘徊迷路 |
ユーザー | letrangerjp |
提出日時 | 2018-03-03 19:23:43 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 1,177 ms / 2,000 ms |
コード長 | 951 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 11,500 KB |
実行使用メモリ | 15,552 KB |
最終ジャッジ日時 | 2023-09-17 04:27:13 |
合計ジャッジ時間 | 10,385 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
15,320 KB |
testcase_01 | AC | 92 ms
15,244 KB |
testcase_02 | AC | 147 ms
15,288 KB |
testcase_03 | AC | 109 ms
15,184 KB |
testcase_04 | AC | 553 ms
15,404 KB |
testcase_05 | AC | 81 ms
15,320 KB |
testcase_06 | AC | 83 ms
15,044 KB |
testcase_07 | AC | 83 ms
15,148 KB |
testcase_08 | AC | 154 ms
15,440 KB |
testcase_09 | AC | 774 ms
15,552 KB |
testcase_10 | AC | 941 ms
15,476 KB |
testcase_11 | AC | 1,160 ms
15,488 KB |
testcase_12 | AC | 84 ms
15,256 KB |
testcase_13 | AC | 1,175 ms
15,376 KB |
testcase_14 | AC | 1,177 ms
15,536 KB |
testcase_15 | AC | 1,173 ms
15,372 KB |
testcase_16 | AC | 1,173 ms
15,312 KB |
コンパイルメッセージ
Syntax OK
ソースコード
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 = [[1,0],[-1,0],[0,1],[0,-1]] BITS_COUNT = [ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, ] flags = R.times.map{ [0]*C } (1...R).each{|y| (1...C).each{|x| next if Board[y][x] == ?# flags[y][x] = DIRS.map.with_index{|(dy, dx), i| Board[y+dy][x+dx] == ?# ? 0 : 1 << i }.inject :| } } state = R.times.map{ [0.0]*C } dp = state.map &:dup dp[Sy][Sx] = 1.0 [T, 10000+T%2].min.times{ next_dp = state.map &:dup (1...R).each{|y| (1...C).each{|x| next if Board[y][x] == ?# dir_count = BITS_COUNT[flags[y][x]] if dir_count == 0 next_dp[y][x] += dp[y][x] next end DIRS.each_with_index{|(dy, dx), d| next if flags[y][x] & (1 << d) == 0 next_dp[y+dy][x+dx] += dp[y][x] / dir_count } } } dp = next_dp } p dp[Gy][Gx].to_f