結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー betit0919betit0919
提出日時 2020-05-29 22:10:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 3,108 bytes
コンパイル時間 1,127 ms
コンパイル使用メモリ 131,752 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 22:47:11
合計ジャッジ時間 2,538 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 38 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 101 ms
6,940 KB
testcase_11 AC 24 ms
6,940 KB
testcase_12 AC 18 ms
6,940 KB
testcase_13 AC 24 ms
6,944 KB
testcase_14 AC 26 ms
6,940 KB
testcase_15 AC 66 ms
6,940 KB
testcase_16 AC 12 ms
6,944 KB
testcase_17 AC 13 ms
6,944 KB
testcase_18 AC 63 ms
6,940 KB
testcase_19 AC 23 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 47 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 100 ms
6,940 KB
testcase_26 AC 99 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 998244353;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

template<int Modulo = MOD>
struct Mint {
	ll val;
	constexpr Mint(ll v = 0) noexcept : val(v % Modulo) { if (val < 0) val += Modulo; }

	constexpr Mint& operator += (const Mint &r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint &r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint &r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint &r) noexcept {
		ll a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}

	constexpr Mint operator + (const Mint &r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint &r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint &r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint &r) const noexcept { return Mint(*this) /= r; }

	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }

	constexpr bool operator == (const Mint &r) const noexcept { return val == r.val; }
	constexpr bool operator != (const Mint &r) const noexcept { return val != r.val; }

	friend ostream &operator << (ostream &os, const Mint<Modulo> &x) noexcept { return os << x.val; }
	friend istream &operator >> (istream &is, Mint<Modulo> &x) noexcept {
		ll tmp; is >> tmp;
		x = Mint(tmp);
		return is;
	}

	constexpr Mint pow(ll n) noexcept {
		Mint res{ 1 }, tmp{ val };
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};
using mint = Mint<>;

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N,Q;
  cin>>N>>Q;
  vector<int>A(N),B(Q);
  REP(i,N){
    cin>>A[i];
  }
  REP(i,Q){
    cin>>B[i];
  }
  // i-1個まで見て、jこのNがある場合の数
  vector<vector<mint>> dp(2, vector<mint>(N+1));
  dp[0][0]=1;
  REP(i,N){
    REP(j,N+1){
      dp[(i+1)%2][j]=0;
    }
    REP(j,N){
      dp[(i+1)%2][j]+=dp[i%2][j]*(A[i]-1);
      dp[(i+1)%2][j+1]+=dp[i%2][j];
    }
  }

  REP(i,Q){
    cout<<dp[N%2][B[i]]<<endl;
  }
}
0