結果

問題 No.2625 Bouns Ai
ユーザー miiitomimiiitomi
提出日時 2024-02-09 23:09:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 348 ms / 2,000 ms
コード長 1,031 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 207,412 KB
実行使用メモリ 160,768 KB
最終ジャッジ日時 2024-02-09 23:09:57
合計ジャッジ時間 9,905 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,676 KB
testcase_01 AC 4 ms
6,676 KB
testcase_02 AC 17 ms
11,008 KB
testcase_03 AC 243 ms
160,768 KB
testcase_04 AC 327 ms
160,768 KB
testcase_05 AC 238 ms
160,768 KB
testcase_06 AC 241 ms
160,768 KB
testcase_07 AC 241 ms
160,768 KB
testcase_08 AC 246 ms
160,768 KB
testcase_09 AC 236 ms
160,768 KB
testcase_10 AC 325 ms
160,768 KB
testcase_11 AC 6 ms
6,676 KB
testcase_12 AC 325 ms
160,768 KB
testcase_13 AC 345 ms
160,768 KB
testcase_14 AC 318 ms
160,768 KB
testcase_15 AC 320 ms
160,768 KB
testcase_16 AC 321 ms
160,768 KB
testcase_17 AC 348 ms
160,768 KB
testcase_18 AC 321 ms
160,768 KB
testcase_19 AC 327 ms
160,768 KB
testcase_20 AC 324 ms
160,768 KB
testcase_21 AC 346 ms
160,768 KB
testcase_22 AC 320 ms
160,768 KB
testcase_23 AC 325 ms
160,768 KB
testcase_24 AC 321 ms
160,768 KB
testcase_25 AC 348 ms
160,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;

void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<vector<ll>> dp(N, vector<ll>((int)1e+5 + 2, 0));

    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= (int)1e+5; j++) dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % MOD;
        if (i == N-1) break;

        int B = 1e+5 - A[i+1];

        for (int j = 0; j <= (int)1e+5; j++) {
            int x = max((ll)j, A[i] + j - A[i+1]);
            if (x <= B) {
                dp[i+1][x] = (dp[i+1][x] + dp[i][j]) % MOD;
                dp[i+1][B+1] = (dp[i+1][B+1] - dp[i][j] + MOD) % MOD;
            }
        }
    }
    ll ans = 0;
    for (int j = 0; j <= (int)1e+5; j++) ans = (ans + dp[N-1][j]) % MOD;
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int T = 1;
    // cin >> T;
    while (T--) solve();
}
0