結果

問題 No.659 徘徊迷路
ユーザー finefine
提出日時 2018-03-02 23:38:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,569 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 168,716 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-04 14:54:04
合計ジャッジ時間 5,177 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int dh[] = {1, -1, 0, 0};
const int dw[] = {0, 0, 1, -1};

double dp[2][10][10];
int cnt[10][10];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r, c, t;
    cin >> r >> c >> t;
    int sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    vector<string> s(r);
    for (int i = 0; i < r; i++) cin >> s[i];
    for (int h = 0; h < r; h++) {
        for (int w = 0; w < c; w++) {
            for (int j = 0; j < 4; j++) {
                int nh = h + dh[j], nw = w + dw[j];
                if (nh < 0 || nh >= r || nw < 0 || nw >= c) continue;
                cnt[h][w] += (s[nh][nw] == '.');               
            }
        }
    }
    dp[0][sy][sx] = 1;
    for (int i = 0; i < max(t, 10000); i++) {
        for (int h = 0; h < r; h++) {
            for (int w = 0; w < c; w++) {
                for (int j = 0; j < 4; j++) {
                    int nh = h + dh[j], nw = w + dw[j];
                    if (nh < 0 || nh >= r || nw < 0 || nw >= c) continue;
                    if (s[nh][nw] == '#') continue;
                    dp[(i + 1) % 2][nh][nw] += dp[i % 2][h][w] / cnt[h][w];
                }
                if (i + 1 < max(t, 10000)) dp[i % 2][h][w] = 0;
            }
        }
    }
    if (t <= 10000) cout << setprecision(10) << dp[t % 2][gy][gx] << endl;
    else {
        if ((t - 10000) % 2 == 1) cout << setprecision(10) << dp[1 - t % 2][gy][gx] << endl;
        else cout << setprecision(10) << dp[t % 2][gy][gx] << endl;
    }
    return 0;
}
0