結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 2 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/all>
using namespace std;
using namespace atcoder;

typedef modint998244353 mint;
typedef long long ll;

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

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--;
		vector<mint> dp(k+1);
		dp[0] = 1;
		for (int j=a; j<b; j++){
			vector<mint> ndp(k+1);
			for (int l=0; l<=k; l++){
				ndp[l] += dp[l];
			}
			for (int l=1; l<=k; l++){
				ndp[l] += dp[l-1] * p[j];
			}
			dp = ndp;
		}
		cout << dp[k].val() << "\n";
	}
}
0