結果
| 問題 |
No.1353 Limited Sequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-17 13:24:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 168 ms / 2,000 ms |
| コード長 | 2,708 bytes |
| コンパイル時間 | 1,161 ms |
| コンパイル使用メモリ | 133,092 KB |
| 最終ジャッジ日時 | 2025-01-18 00:26:31 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>
using namespace std;
typedef long long ll;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); }return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353;
struct mint {
long long x;
mint(long long x = 0) :x((x% mod + mod) % mod) {}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod - a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
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;
}
// for prime mod
mint inv() const {
return pow(mod - 2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
int main()
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n, L, R; cin >> n >> L >> R;
vector<int> a(n); for (auto& e : a) cin >> e;
vector dp(R + 1, vector<mint>(n + 1));
for (int i = 0; i < n; i++) {
for (int cnt = 1; cnt * (i + 1) <= R and cnt <= a[i]; cnt++) {
dp[(i + 1) * cnt][i] = 1;
}
}
for (int i = 0; i <= R; i++) {
mint sum = 0;
for (int j = 0; j < n; j++) {
sum += dp[i][j];
}
for (int j = 0; j < n; j++) {
for (int cnt = 1; i + cnt * (j + 1) <= R and cnt <= a[j]; cnt++) {
dp[i + cnt * (j + 1)][j] += sum - dp[i][j];
}
}
}
mint res = 0; for (int i = L; i <= R; i++) for (auto& e : dp[i]) res += e;
cout << res.x << "\n";
}