結果

問題 No.2430 Damage Zone
ユーザー ramdosramdos
提出日時 2023-08-11 15:36:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 2,302 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 209,592 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-29 09:16:33
合計ジャッジ時間 3,583 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
11,904 KB
testcase_01 AC 10 ms
8,192 KB
testcase_02 AC 25 ms
18,304 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 26 ms
19,456 KB
testcase_15 AC 25 ms
19,456 KB
testcase_16 AC 26 ms
19,456 KB
testcase_17 AC 7 ms
6,272 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 11 ms
9,600 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 9 ms
7,936 KB
testcase_26 AC 13 ms
10,240 KB
testcase_27 AC 8 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()    // sortなどの引数を省略
#define max3(x, y, z) max(x, max(y, z))  // 3変数max
#define min3(x, y, z) min(x, min(y, z))  // 3変数min
#define chmin(m, v) m = min((m), (v))    //最小値を更新
#define chmax(m, v) m = max((m), (v))    //最大値を更新
#define rep(i, n) repi(i, 0, n)          // 0-N rep
#define reps(i, n) repi(i, 1, n + 1)     // 1-N
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); i++)  // a-b


const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
signed main(){
    ll H,W,K;
    cin >> H >> W >> K;
    vector<string> v(H);
    rep(i,H){
        cin >> v[i];
    }
    vector<vector<vector<mint>>> dp(H,vector<vector<mint>>(W,vector<mint>(K)));
    dp[0][0][0]=1;
    rep(i,H){
        rep(j,W){
            rep(k,K){
                if(v[i][j]=='.'){
                    if(i!=0)dp[i][j][k]+=dp[i-1][j][k];
                    if(j!=0)dp[i][j][k]+=dp[i][j-1][k];
                }
                if(v[i][j]=='o'){
                    if(i!=0 and k!=0)dp[i][j][k]+=dp[i-1][j][k-1];
                    if(j!=0 and k!=0)dp[i][j][k]+=dp[i][j-1][k-1];
                }
            }
        }
    }
    mint ans = 0;
    rep(i,K){
        ans+=dp[H-1][W-1][i];
    }
    cout << ans << endl;
}
0