結果

問題 No.659 徘徊迷路
ユーザー どららどらら
提出日時 2018-03-02 23:20:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,346 bytes
コンパイル時間 2,902 ms
コンパイル使用メモリ 175,416 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-04 12:00:15
合計ジャッジ時間 12,315 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 107 ms
4,384 KB
testcase_03 AC 60 ms
4,384 KB
testcase_04 AC 605 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 908 ms
4,380 KB
testcase_10 AC 1,066 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1,352 ms
4,380 KB
testcase_14 AC 1,348 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int vy[4] = {-1,1,0,0};
int vx[4] = {0,0,-1,1};

int main(){
  int R, C, T;
  cin >> R >> C >> T;
  int Sy, Sx, Gy, Gx;
  cin >> Sy >> Sx;
  cin >> Gy >> Gx;
  vector<string> B(R);
  rep(i,R){
    cin >> B[i];
  }

  vector<vector<double>> prev(R,vector<double>(C,0)), next(R,vector<double>(C,0));
  prev[Sy][Sx] = 1.0;
  rep(t,min(T,1000000)){
    /*
    cout << t << endl;
    rep(i,R){
      rep(j,C){
        cout << prev[i][j] << "\t";
      }
      cout << endl;
    }
    cout << endl;
     */
    rep(i,R) rep(j,C) next[i][j] = 0;
    rep(i,R) rep(j,C){
      if(B[i][j] == '#') continue;
      int cnt = 0;
      rep(k,4){
        int ny = i + vy[k];
        int nx = j + vx[k];
        if(B[ny][nx] == '.') cnt++;
      }
      if(cnt == 0){
        next[i][j] = prev[i][j];
      }else{
        rep(k,4){
          int ny = i + vy[k];
          int nx = j + vx[k];
          if(B[ny][nx] == '.') next[ny][nx] += 1.0 / cnt * prev[i][j];
        }
      }
    }
    prev = next;
  }

  printf("%.12lf\n", prev[Gy][Gx]);
  
  return 0;
}
0