結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー HaaHaa
提出日時 2020-05-29 21:56:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 1,380 ms
コンパイル使用メモリ 165,280 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 21:56:32
合計ジャッジ時間 2,487 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 24 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 58 ms
5,376 KB
testcase_11 AC 15 ms
5,376 KB
testcase_12 AC 12 ms
5,376 KB
testcase_13 AC 15 ms
5,376 KB
testcase_14 AC 16 ms
5,376 KB
testcase_15 AC 40 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 38 ms
5,376 KB
testcase_19 AC 14 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 29 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 65 ms
5,376 KB
testcase_26 AC 62 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int n, q; cin >> n >> q;
	VI a(n); REP(i,n) cin >> a[i];
	VI dp(n+1,0);
	VI dp2(n+1,0);
	dp[0]=1;
	REP(i,n){
		REP(j,i+1){
			dp2[j+1]+=dp[j];
			dp2[j]+=dp[j]*(a[i]-1);
			dp2[j]%=MOD;
		}
		dp2[i]%=MOD;
		REP(j,i+2){
			dp[j]=dp2[j];
			dp2[j]=0;
		}
	}
	VI b(q); REP(i,q) cin >> b[i];
	REP(i,q){
		cout << dp[b[i]] << endl;
	}
	return 0;
}
0