結果

問題 No.659 徘徊迷路
ユーザー letrangerjpletrangerjp
提出日時 2018-03-03 19:22:08
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 948 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 11,484 KB
実行使用メモリ 29,784 KB
最終ジャッジ日時 2023-09-17 04:21:33
合計ジャッジ時間 5,772 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
19,516 KB
testcase_01 AC 143 ms
15,648 KB
testcase_02 AC 107 ms
15,188 KB
testcase_03 AC 85 ms
15,352 KB
testcase_04 AC 997 ms
19,656 KB
testcase_05 AC 68 ms
15,060 KB
testcase_06 AC 68 ms
15,368 KB
testcase_07 AC 69 ms
15,248 KB
testcase_08 AC 443 ms
17,136 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = [[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{ [0r]*C }
dp = state.map &:dup
dp[Sy][Sx] = 1r
[T, 5000+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
0