結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー akun0716akun0716
提出日時 2020-05-30 09:21:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 2,188 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 85,860 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 19:03:39
合計ジャッジ時間 2,240 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 31 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 67 ms
5,376 KB
testcase_11 AC 20 ms
5,376 KB
testcase_12 AC 16 ms
5,376 KB
testcase_13 AC 19 ms
5,376 KB
testcase_14 AC 21 ms
5,376 KB
testcase_15 AC 45 ms
5,376 KB
testcase_16 AC 11 ms
5,376 KB
testcase_17 AC 12 ms
5,376 KB
testcase_18 AC 45 ms
5,376 KB
testcase_19 AC 19 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 33 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 65 ms
5,376 KB
testcase_26 AC 66 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 998244353
//priority_queue<int,vector<int>, greater<int> > q2;


ll comb(ll N_, ll C_) {
	const int NUM_ = 400001;
	static ll fact[400002], factr[400002], inv[400002];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mod, factr[i] = factr[i - 1] * inv[i] % mod;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mod*factr[N_ - C_] % mod;
}
ll modpow(ll a, ll n = mod - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mod, a = a * a%mod, n >>= 1;
	return r;
}
long long modinv(long long a) {
	return modpow(a, mod - 2);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, Q; cin >> N >> Q;
	VI A(N);
	REP(i, N)cin >> A[i];
	int dp[2][6010] = { 0 };
	dp[0][0] = 1;
	REP(i, N) {
		eREP(j, i) {

			int tmp = dp[i % 2][j] * (A[i] - 1);
			dp[(i + 1) % 2][j] += tmp;
			dp[(i + 1) % 2][j + 1] += dp[i % 2][j];
			dp[(i + 1) % 2][j] %= mod;
			dp[(i + 1) % 2][j + 1] %= mod;
		}
		REP(k, 6010)dp[i % 2][k] = 0;
	}


	while (Q--) {
		int a; cin >> a;
		cout << dp[N % 2][a] << endl;
	}

	return 0;
}

0