結果

問題 No.2003 Frog on Grid
ユーザー milanis48663220milanis48663220
提出日時 2022-07-12 03:05:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,452 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 125,720 KB
実行使用メモリ 814,888 KB
最終ジャッジ日時 2023-09-05 01:32:48
合計ジャッジ時間 6,368 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 RE -
testcase_11 AC 33 ms
40,592 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 59 ms
74,600 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 21 ms
19,964 KB
testcase_18 AC 56 ms
51,372 KB
testcase_19 MLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint998244353;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int h, w, k; cin >> h >> w >> k;
    vector<string> s(h);
    for(int i = 0; i < h; i++) cin >> s[i];
    auto dp = vec2d(h+w+5, h+w+5, mint(0));
    auto hor = vec2d(h+w+5, h+w+5, mint(0));
    auto stop = vec2d(h+w+5, h+w+5, mint(0));
    vector<mint> cumsum(h+w+5);
    dp[0][0] = 1;
    hor[0][0] = 1;
    hor[0][k+1] -= 1;
    stop[1][k] -= 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; i+j < h+w; j++){
            if(i > 0) stop[i][j] += stop[i-1][j+1];
            if(j > 0) hor[i][j] += hor[i][j-1];
            cumsum[j] += hor[i][j]+stop[i][j];
            dp[i][j] = cumsum[j];
            if(i == 0 && j == 0) continue;
            if(j < w && s[i][j] == '.'){
                hor[i][j] += dp[i][j];
                hor[i][j+k+1] -= dp[i][j];
                cumsum[j] += dp[i][j];
                // cumsum[j+k+1] -= dp[i][j];
                stop[i+1][j+k] -= dp[i][j];
                if(j > 0) stop[i+k+2][j-1] += dp[i][j];
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
}
0