結果

問題 No.2369 Some Products
ユーザー shobonvipshobonvip
提出日時 2023-06-30 03:26:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 503 ms / 2,500 ms
コード長 897 bytes
コンパイル時間 7,448 ms
コンパイル使用メモリ 264,196 KB
実行使用メモリ 198,996 KB
最終ジャッジ日時 2023-09-21 14:40:44
合計ジャッジ時間 11,513 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 501 ms
198,996 KB
testcase_03 AC 503 ms
198,880 KB
testcase_04 AC 502 ms
198,884 KB
testcase_05 AC 37 ms
15,232 KB
testcase_06 AC 454 ms
198,672 KB
testcase_07 AC 34 ms
16,548 KB
testcase_08 AC 88 ms
38,140 KB
testcase_09 AC 30 ms
12,136 KB
testcase_10 AC 172 ms
71,112 KB
testcase_11 AC 342 ms
150,660 KB
testcase_12 AC 19 ms
9,008 KB
testcase_13 AC 209 ms
87,744 KB
testcase_14 AC 241 ms
103,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint998244353 mint;
typedef long long ll;

int main(){
	int n; cin >> n;
	vector<mint> p(n);
	for (int i=0; i<n; i++){
		int x; cin >> x;
		p[i] = x;
	}

	vector<vector<mint>> f(n+1, vector<mint>(n+1));
	vector<vector<mint>> g(n+1, vector<mint>(n+1));
	f[0][0] = 1;
	g[0][0] = 1;
	for (int i=0; i<n; i++){
		for (int j=0; j<n+1; j++){
			f[i+1][j] += f[i][j];
		}
		for (int j=1; j<n+1; j++){
			f[i+1][j] += f[i][j-1] * p[i];
		}
	}
	for (int i=0; i<n; i++){
		for (int j=0; j<n+1; j++){
			g[i+1][j] = g[i][j];
		}
		for (int j=1; j<n+1; j++){
			g[i+1][j] += g[i+1][j-1] * (-p[i]);
		}
	}
	int q; cin >> q;
	for (int i=0; i<q; i++){
		int a, b, k; cin >> a >> b >> k;
		a--;
		mint ans = 0;
		for (int j=0; j<k+1; j++){
			ans += f[b][j] * g[a][k-j];
		}
		cout << ans.val() << "\n";
	}
	
}
0