結果

問題 No.659 徘徊迷路
ユーザー ikdikd
提出日時 2018-03-03 00:51:03
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 1,312 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 151,952 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-03 18:57:59
合計ジャッジ時間 5,084 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 53 ms
4,376 KB
testcase_03 AC 46 ms
4,380 KB
testcase_04 AC 149 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 211 ms
4,504 KB
testcase_10 AC 230 ms
4,376 KB
testcase_11 AC 271 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 270 ms
4,380 KB
testcase_14 AC 270 ms
4,376 KB
testcase_15 AC 270 ms
4,376 KB
testcase_16 AC 272 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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));
  }
}
0