結果

問題 No.2625 Bouns Ai
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-02-29 13:22:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 651 ms / 2,000 ms
コード長 3,019 bytes
コンパイル時間 2,930 ms
コンパイル使用メモリ 207,032 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-29 13:22:52
合計ジャッジ時間 14,610 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,676 KB
testcase_01 AC 5 ms
6,676 KB
testcase_02 AC 30 ms
6,676 KB
testcase_03 AC 10 ms
6,676 KB
testcase_04 AC 614 ms
6,676 KB
testcase_05 AC 11 ms
6,676 KB
testcase_06 AC 11 ms
6,676 KB
testcase_07 AC 11 ms
6,676 KB
testcase_08 AC 14 ms
6,676 KB
testcase_09 AC 11 ms
6,676 KB
testcase_10 AC 613 ms
6,676 KB
testcase_11 AC 8 ms
6,676 KB
testcase_12 AC 596 ms
6,676 KB
testcase_13 AC 651 ms
6,676 KB
testcase_14 AC 614 ms
6,676 KB
testcase_15 AC 639 ms
6,676 KB
testcase_16 AC 609 ms
6,676 KB
testcase_17 AC 639 ms
6,676 KB
testcase_18 AC 602 ms
6,676 KB
testcase_19 AC 641 ms
6,676 KB
testcase_20 AC 599 ms
6,676 KB
testcase_21 AC 610 ms
6,676 KB
testcase_22 AC 599 ms
6,676 KB
testcase_23 AC 614 ms
6,676 KB
testcase_24 AC 588 ms
6,676 KB
testcase_25 AC 612 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

//RSQ (0-indexed)
template<class T> struct BIT {
    private:
        vector<T> bit; int N;
        T _sum(int r){
            r++; T res = 0;
            while(r > 0) res += bit[r-1], r -= r & -r;
            return res;
        }

    public:
        BIT (int n){ N = n; bit.resize(N);}
        BIT (vector<T> &a) : BIT(a.size()) { for (int i=0; i<N; i++) add(i, a[i]);}
        void add(int loc, T val){
            loc++;
            while(loc <= N) bit[loc-1] += val, loc += loc & -loc;
        }
        void change(int loc, T val){add(loc, -get(loc)+val);}
        T sum(int l, int r) {return _sum(r) - _sum(l-1);}
        T get(int l) {return sum(l, l);}
        void clear() {for (int i=0; i<N; i++) bit[i] = 0;}
};

const ll modc = 998244353;
class mint {
    ll x;
public:
    mint(ll x=0) : x((x%modc+modc)%modc) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += modc-a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= modc;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=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(modc-2);}
    mint& operator/=(const mint& a){ return (*this) *= a.inv();}
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    bool operator == (const mint& a) const{ return x == a.x;}
    bool operator != (const mint& a) const{ return x != a.x;}
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    friend istream& operator>>(istream& ip, mint &m) {
        ll t;
        ip >> t;
        m = mint(t);
        return ip;
    }
    ll val(){ return x;}
};

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

    //dp(i, j) = i番目のプレイヤーの仮のスコアがjであるような場合の数
    //k <= j
    //k+A_(i-1) <= j+A_i <= 1e5
    //k = 0, 1, ..., min(j+A_i-A_(i-1), j)からの遷移(0<=j<=1e5-A_i)

    int N, M=1e5;
    cin >> N;
    vector<int> A(N+1);
    for (int i = 1; i <= N; ++i) cin >> A[i];
    BIT<mint> dp(M+1);
    for (int i=0; i<=M-A[1]; i++) dp.add(i, 1);

    for (int i=2; i<=N; i++){
        BIT<mint> dp2(M+1);
        for (int j=0; j<=M-A[i]; j++){
            dp2.add(j, dp.sum(0, min(j+A[i]-A[i-1], j)));
        }
        swap(dp, dp2);
    }

    mint ans = 0;
    cout << dp.sum(0, M) << endl;

    return 0;
}
0