結果

問題 No.2625 Bouns Ai
ユーザー GOTKAKOGOTKAKO
提出日時 2024-02-09 22:15:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 2,526 bytes
コンパイル時間 2,100 ms
コンパイル使用メモリ 208,752 KB
実行使用メモリ 161,664 KB
最終ジャッジ日時 2024-02-09 22:15:14
合計ジャッジ時間 11,023 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,548 KB
testcase_01 AC 7 ms
6,548 KB
testcase_02 AC 25 ms
11,904 KB
testcase_03 AC 121 ms
161,664 KB
testcase_04 AC 461 ms
161,664 KB
testcase_05 AC 123 ms
161,664 KB
testcase_06 AC 121 ms
161,664 KB
testcase_07 AC 121 ms
161,664 KB
testcase_08 AC 144 ms
161,664 KB
testcase_09 AC 122 ms
161,664 KB
testcase_10 AC 461 ms
161,664 KB
testcase_11 AC 7 ms
7,168 KB
testcase_12 AC 436 ms
161,664 KB
testcase_13 AC 435 ms
161,664 KB
testcase_14 AC 435 ms
161,664 KB
testcase_15 AC 432 ms
161,664 KB
testcase_16 AC 435 ms
161,664 KB
testcase_17 AC 435 ms
161,664 KB
testcase_18 AC 461 ms
161,664 KB
testcase_19 AC 435 ms
161,664 KB
testcase_20 AC 433 ms
161,664 KB
testcase_21 AC 432 ms
161,664 KB
testcase_22 AC 448 ms
161,664 KB
testcase_23 AC 426 ms
161,664 KB
testcase_24 AC 425 ms
161,664 KB
testcase_25 AC 424 ms
161,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long mod = 998244353;
//入力が必ずmod未満の時に使う.
struct mint{
    long long v = 0;
    mint(){} mint(int a){v = a;} mint(long long a){v = a;} mint(unsigned long long a){v = a;}
    long long val(){return v;}
    void modu(){v %= mod;}
 
    mint repeat2mint(long long a,long long b){
        mint ret = 1,p = a; int Log = 60;
        if(b <= 2e9) Log = 30;
        for(int i=0; i<Log; i++){if(b&(1LL<<i)) ret *= p; p *= p;}
        return ret;
    };
 
    mint operator+(mint b){return (v+b.v)%mod;}
    mint operator-(mint b){return (v-b.v+mod)%mod;}
    mint operator*(mint b){return v*b.v%mod;}
    mint operator/(mint b){
        if(b.v == 0) assert(false);
        return v*(repeat2mint(b.v,mod-2)).v%mod;
    }
 
    void operator+=(mint b){v = (v+b.v)%mod;}
    void operator-=(mint b){v = (v-b.v+mod)%mod;}
    void operator*=(mint b){v = v*b.v%mod;}
    void operator/=(mint b){
    if(b.v == 0) assert(false);
        v = v*repeat2mint(b.v,mod-2).v%mod;
    }
 
    void operator++(int){v = (v+1)%mod; return;}
    void operator--(int){v = (v-1+mod)%mod; return;}
    bool operator==(mint b){if(v == b.v) return true; else return false;}
    bool operator!=(mint b){if(v != b.v) return true; else return false;}
    bool operator>(mint b){if(v > b.v) return true; else return false;}
    bool operator>=(mint b){if(v >= b.v) return true; else return false;}
    bool operator<(mint b){if(v < b.v) return true; else return false;}
    bool operator<=(mint b){if(v <= b.v) return true; else return false;}
 
    mint pow(long long x){return repeat2mint(v,x);}
    mint inv(){return mint(1)/v;}
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    vector<int> A(N);
    for(auto &a : A) cin >> a;

    vector<vector<mint>> dp(N+1,vector<mint>(100001));
    dp.at(0).at(0) = 1;
    for(int i=0; i<N; i++){
        int a0 = 0,a1 = A.at(i);
        if(i) a0 = A.at(i-1);
        
        if(a1-a0 >= 0){
            mint sum = 0;
            for(int k=0; k<=100000-a1; k++){
                sum += dp.at(i).at(k);
                dp.at(i+1).at(k) = sum;
            }
        }
        else{
            int diff = a0-a1;
            mint sum = 0;
            for(int k=diff; k<=100000-a1; k++){
                sum += dp.at(i).at(k-diff);
                dp.at(i+1).at(k) = sum;
            }
        }
    }

    mint answer = 0;
    for(auto d : dp.back()) answer += d;
    cout << answer.v << endl;
}
0