結果

問題 No.1353 Limited Sequence
ユーザー hitonanodehitonanode
提出日時 2021-05-14 16:28:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 79,384 KB
最終ジャッジ日時 2025-01-21 10:56:19
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
#include <atcoder/modint>
using mint = atcoder::modint998244353;

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N, L, R;
    cin >> N >> L >> R;
    vector<int> A(N);
    for (auto &a : A) cin >> a;

    vector dp(R + 1, vector<mint>(N + 1)); // (sum, last)
    dp[0][0] = 1;
    mint ret = 0;
    for (int s = 0; s < R; s++) {
        const mint f = accumulate(dp[s].begin(), dp[s].end(), mint(0));
        for (int a = 1; a <= N; a++) {
            for (int n = 1; n <= A[a - 1]; n++) {
                int t = s + n * a;
                if (t > R) break;
                dp[t][a] += f - dp[s][a];
                if (t >= L) ret += f - dp[s][a];
            }
        }
    }
    cout << ret.val() << '\n';
}
0