結果
問題 | No.2625 Bouns Ai |
ユーザー |
![]() |
提出日時 | 2024-02-29 13:22:37 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 603 ms / 2,000 ms |
コード長 | 3,019 bytes |
コンパイル時間 | 2,206 ms |
コンパイル使用メモリ | 205,704 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-09-29 12:41:10 |
合計ジャッジ時間 | 12,432 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#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;}