結果
| 問題 |
No.659 徘徊迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-03-03 19:22:08 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 948 bytes |
| コンパイル時間 | 39 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 20,000 KB |
| 最終ジャッジ日時 | 2024-07-04 01:54:03 |
| 合計ジャッジ時間 | 4,131 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 TLE * 1 |
| other | -- * 12 |
コンパイルメッセージ
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{ [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