結果

問題 No.3071 Double Speedrun
ユーザー nonon
提出日時 2025-03-21 21:58:00
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3,672 ms / 6,000 ms
コード長 1,465 bytes
コンパイル時間 3,388 ms
コンパイル使用メモリ 287,880 KB
実行使用メモリ 8,624 KB
最終ジャッジ日時 2025-03-21 21:58:42
合計ジャッジ時間 37,622 ms
ジャッジサーバーID
(参考情報)
judge5 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using mint = atcoder::modint998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) cin >> S[i];
    int N = H + W + 1;
    vector<vector<mint>> dp(N, vector<mint>(N));
    dp[1][0] = 1;
    for (int t = 1; t < N - 3; t++) {
        vector<vector<mint>> ep(N, vector<mint>(N));
        for (int i = 0; i < N - 1; i++) {
            for (int j = 0; j < N - 1; j++) {
                int ar = i, ac = t - i;
                int br = j, bc = t - j;
                if (ac < 0 || bc < 0) continue;
                for (int x : {0, 1}) {
                    int xr = ar, xc = ac;
                    (x ? xr : xc)++;
                    if (0 <= xr && xr < H && 0 <= xc && xc < W && S[xr][xc] == '.') {
                        for (int y : {0, 1}) {
                            int yr = br, yc = bc;
                            (y ? yr : yc)++;
                            if (0 <= yr && yr < H && 0 <= yc && yc < W && S[yr][yc] == '.') {
                                if (t == N - 4 || xr != yr) {
                                    ep[xr][yr] += dp[i][j];
                                }
                            }
                        }
                    }
                }
            }
        }
        dp = ep;
    }
    cout << dp[H - 1][H - 1].val() << endl;
}
0