結果

問題 No.659 徘徊迷路
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-03-02 23:33:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,956 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 175,800 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-04 13:48:01
合計ジャッジ時間 3,700 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,384 KB
testcase_01 AC 20 ms
4,380 KB
testcase_02 AC 56 ms
4,384 KB
testcase_03 WA -
testcase_04 AC 56 ms
4,380 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 16 ms
4,384 KB
testcase_07 AC 15 ms
4,380 KB
testcase_08 AC 23 ms
4,380 KB
testcase_09 AC 56 ms
4,380 KB
testcase_10 AC 64 ms
4,388 KB
testcase_11 AC 64 ms
4,384 KB
testcase_12 AC 12 ms
4,384 KB
testcase_13 AC 56 ms
4,380 KB
testcase_14 AC 56 ms
4,384 KB
testcase_15 AC 65 ms
4,380 KB
testcase_16 AC 66 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
typedef vector<double> Vec;
typedef vector<Vec> Mat;
Vec mulMatVec(Mat a, Vec b)
{
    int n = b.size(); Vec ret(n, 0);
    rep(i, 0, n) rep(j, 0, n) ret[i] += a[i][j] * b[j];
    return ret;
}
Mat mulMatMat(Mat a, Mat b)
{
    int n = a.size(); Mat ret(n, Vec(n, 0));
    rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] += a[i][k] * b[k][j];
    return ret;
}
Mat fastpow(Mat x, ll n)
{
    Mat ret(x.size(), Vec(x.size(), 0));
    rep(i, 0, x.size()) ret[i][i] = 1;
    while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } }
    return ret;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/
 







int H, W, T, SY, SX, GY, GX;
string B[10];
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W >> T >> SY >> SX >> GY >> GX;
    rep(y, 0, H) cin >> B[y];

    Vec v(100);
    v[SY * 10 + SX] = 1;
    
    Mat m(100, Vec(100));
    rep(y, 0, H) rep(x, 0, W) if(B[y][x] == '.'){
        int cnt = 0;
        rep(i, 0, 4) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if (0 <= xx and xx < W and 0 <= yy and yy < H) {
                if (B[yy][xx] == '.') cnt++;
            }
        }

        double p = 1.0 / (double)cnt;
        rep(i, 0, 4) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if (0 <= xx and xx < W and 0 <= yy and yy < H) if (B[yy][xx] == '.') {
                m[yy * 10 + xx][y * 10 + x] = p;
            }
        }
    }

    v = mulMatVec(fastpow(m, T), v);

    //rep(y, 0, H) rep(x, 0, W) printf("[%d][%d] = %.10f\n", y, x, v[y * 10 + x]);

    double ans = v[GY * 10 + GX];
    printf("%.10f\n", ans);
}
0