結果

問題 No.659 徘徊迷路
ユーザー どららどらら
提出日時 2018-03-02 23:24:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,516 ms / 2,000 ms
コード長 1,353 bytes
コンパイル時間 1,924 ms
コンパイル使用メモリ 174,892 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 12:27:29
合計ジャッジ時間 13,442 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 104 ms
4,380 KB
testcase_03 AC 54 ms
4,380 KB
testcase_04 AC 633 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 972 ms
4,384 KB
testcase_10 AC 1,167 ms
4,380 KB
testcase_11 AC 1,507 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1,516 ms
4,384 KB
testcase_14 AC 1,514 ms
4,380 KB
testcase_15 AC 1,513 ms
4,384 KB
testcase_16 AC 1,515 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

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 + T%2)){
    /*
    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