結果

問題 No.2369 Some Products
ユーザー shobonvipshobonvip
提出日時 2023-06-30 00:39:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 787 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 201,488 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-21 14:21:00
合計ジャッジ時間 6,403 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;
typedef modint998244353 mint;

// DP によって O(N^2 Q)
// dp[i][j] : i-1 番目まで見た時 j 個使用するときの積の総和
// これ、おそらく非想定(実際に O(NQ log^2 N) が可能, Mo もいける?)だけど、
// 愚直ですごい間に合う気がする

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