結果
| 問題 |
No.659 徘徊迷路
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2018-03-03 00:51:03 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 259 ms / 2,000 ms |
| コード長 | 1,312 bytes |
| コンパイル時間 | 2,526 ms |
| コンパイル使用メモリ | 150,396 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-13 00:03:49 |
| 合計ジャッジ時間 | 4,699 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 12 |
ソースコード
void main(){
import std.stdio, std.string, std.conv, std.algorithm;
int h, w, t; rd(h, w, t);
int sy, sx; rd(sy, sx);
int gy, gx; rd(gy, gx);
auto c=new char[][](h, w);
foreach(i; 0..h) c[i]=readln.chomp.to!(char[]);
const double eps=1e-9;
const int[][] dir=[[1, 0], [-1, 0], [0, 1], [0, -1]];
auto dp=new double[][](h, w);
foreach(i; 0..h) fill(dp[i], 0.0);
dp[sy][sx]=1.0;
foreach(_; 0..min(t, 1_000_00+t%2)){
auto nex=new double[][](h, w);
foreach(i; 0..h) fill(nex[i], 0.0);
foreach(i; 0..h)foreach(j; 0..w){
if(c[i][j]=='#') continue;
if(dp[i][j]<eps) continue;
int sum=0;
foreach(d; dir){
auto ni=i+d[0], nj=j+d[1];
if((0<ni && ni<h && 0<nj && nj<w)==false) continue;
if(c[ni][nj]=='#') continue;
sum++;
}
if(sum==0){nex[i][j]=dp[i][j]; continue;}
foreach(d; dir){
auto ni=i+d[0], nj=j+d[1];
if((0<ni && ni<h && 0<nj && nj<w)==false) continue;
if(c[ni][nj]=='#') continue;
nex[ni][nj]+=dp[i][j]/sum;
}
}
dp.swap(nex);
}
writefln("%.18f", dp[gy][gx]);
}
void rd(T...)(ref T x){
import std.stdio, std.string, std.conv;
auto l=readln.split;
assert(l.length==x.length);
foreach(i, ref e; x){
e=l[i].to!(typeof(e));
}
}
ikd