結果

問題 No.1353 Limited Sequence
ユーザー QCFiumQCFium
提出日時 2021-01-17 14:54:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,030 ms / 2,000 ms
コード長 3,334 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 176,856 KB
実行使用メモリ 312,704 KB
最終ジャッジ日時 2024-05-07 03:57:43
合計ジャッジ時間 19,807 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 396 ms
152,960 KB
testcase_13 AC 302 ms
149,248 KB
testcase_14 AC 130 ms
68,480 KB
testcase_15 AC 371 ms
146,432 KB
testcase_16 AC 36 ms
20,864 KB
testcase_17 AC 87 ms
44,160 KB
testcase_18 AC 447 ms
151,680 KB
testcase_19 AC 628 ms
233,856 KB
testcase_20 AC 154 ms
70,912 KB
testcase_21 AC 35 ms
18,688 KB
testcase_22 AC 67 ms
35,584 KB
testcase_23 AC 357 ms
140,928 KB
testcase_24 AC 249 ms
99,072 KB
testcase_25 AC 526 ms
197,248 KB
testcase_26 AC 234 ms
97,024 KB
testcase_27 AC 126 ms
56,704 KB
testcase_28 AC 163 ms
81,280 KB
testcase_29 AC 89 ms
46,464 KB
testcase_30 AC 281 ms
120,832 KB
testcase_31 AC 194 ms
80,512 KB
testcase_32 AC 328 ms
127,616 KB
testcase_33 AC 73 ms
44,160 KB
testcase_34 AC 580 ms
214,656 KB
testcase_35 AC 151 ms
70,528 KB
testcase_36 AC 160 ms
93,440 KB
testcase_37 AC 1,001 ms
312,448 KB
testcase_38 AC 989 ms
312,704 KB
testcase_39 AC 1,016 ms
312,576 KB
testcase_40 AC 993 ms
312,448 KB
testcase_41 AC 974 ms
312,448 KB
testcase_42 AC 989 ms
312,448 KB
testcase_43 AC 981 ms
312,448 KB
testcase_44 AC 1,030 ms
312,320 KB
testcase_45 AC 983 ms
312,448 KB
testcase_46 AC 990 ms
312,576 KB
testcase_47 AC 920 ms
312,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

template<int mod>
struct ModInt{
	int x;
	ModInt () : x(0) {}
	ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {}
	ModInt &operator += (const ModInt &p){
		if ((x += p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator -= (const ModInt &p) {
		if ((x += mod - p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator *= (const ModInt &p) {
		x = (int64_t) x * p.x % mod;
		return *this;
	}
	ModInt &operator /= (const ModInt &p) {
		*this *= p.inverse();
		return *this;
	}
	ModInt &operator ^= (int64_t p) {
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator - () const { return ModInt(-x); }
	ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
	ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
	ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
	ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
	ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; }
	bool operator == (const ModInt &p) const { return x == p.x; }
	bool operator != (const ModInt &p) const { return x != p.x; }
	explicit operator int() const { return x; }
	ModInt &operator = (const int p) { x = p; return *this;}
	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			a -= t * b;
			std::swap(a, b);
			u -= t * v;
			std::swap(u, v);
		}
		return ModInt(u);
	}
	friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) {
		return stream << p.x;
	}
	friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) {
		int64_t x;
		stream >> x;
		a = ModInt<mod>(x);
		return stream;
	}
};
typedef ModInt<998244353> mint;

template<int mod> struct MComb {
	using mint = ModInt<mod>;
	std::vector<mint> fact;
	std::vector<mint> inv;
	MComb (int n) { // O(n + log(mod))
		fact = std::vector<mint>(n + 1, 1);
		for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i);
		inv.resize(n + 1);
		inv[n] = fact[n] ^ (mod - 2);
		for (int i = n; i--; ) inv[i] = inv[i + 1] * mint(i + 1);
	}
	mint ncr(int n, int r) {
		return fact[n] * inv[r] * inv[n - r];
	}
	mint npr(int n, int r) {
		return fact[n] * inv[n - r];
	}
	mint nhr(int n, int r) {
		assert(n + r - 1 < (int) fact.size());
		return ncr(n + r - 1, r);
	}
};


int main() {
	int n = ri();
	int l = ri();
	int r = ri();
	std::vector<int> a(n);
	for (auto &i : a) i = ri();
	
	std::vector<std::vector<mint> > dp[r + 1];
	for (auto &i : dp) {
		i.resize(n);
		for (int j = 0; j < n; j++) i[j].resize(r / (j + 1) + 1);
	}
	for (int i = 0; i < n; i++) if (i + 1 <= r) dp[i + 1][i][1] = 1;
	for (int i = 0; i <= r; i++) {
		mint sum = 0;
		mint minus[n];
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < (int) dp[i][j].size(); k++) {
				if (dp[i][j][k] == 0) continue;
				sum += dp[i][j][k];
				minus[j] += dp[i][j][k];
				if (i + j + 1 <= r && k < a[j]) dp[i + j + 1][j][k + 1] += dp[i][j][k];
			}
		}
		for (int j = 0; j < n; j++) if (i + j + 1 <= r) dp[i + j + 1][j][1] += sum - minus[j];
	}
	mint res = 0;
	for (int i = l; i <= r; i++) for (auto j : dp[i]) for (auto k : j) res += k;
	std::cout << res << std::endl;
	
	return 0;
}
0