結果
問題 | No.1066 #いろいろな色 / Red and Blue and more various colors (Easy) |
ユーザー | toma |
提出日時 | 2020-05-29 22:03:32 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 2,787 bytes |
コンパイル時間 | 1,719 ms |
コンパイル使用メモリ | 174,136 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 04:44:39 |
合計ジャッジ時間 | 3,031 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 35 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 82 ms
6,820 KB |
testcase_11 | AC | 22 ms
6,816 KB |
testcase_12 | AC | 17 ms
6,816 KB |
testcase_13 | AC | 22 ms
6,816 KB |
testcase_14 | AC | 23 ms
6,820 KB |
testcase_15 | AC | 57 ms
6,820 KB |
testcase_16 | AC | 11 ms
6,820 KB |
testcase_17 | AC | 12 ms
6,816 KB |
testcase_18 | AC | 54 ms
6,816 KB |
testcase_19 | AC | 21 ms
6,820 KB |
testcase_20 | AC | 2 ms
6,820 KB |
testcase_21 | AC | 41 ms
6,820 KB |
testcase_22 | AC | 2 ms
6,820 KB |
testcase_23 | AC | 2 ms
6,820 KB |
testcase_24 | AC | 2 ms
6,816 KB |
testcase_25 | AC | 87 ms
6,820 KB |
testcase_26 | AC | 84 ms
6,816 KB |
ソースコード
#include"bits/stdc++.h" using namespace std; #define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++) #define rep(i,n) REP((i),0,(n)) using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using tp3 = tuple<int, int, int>; using Mat = vector<vector<ll>>; constexpr int INF = 1 << 28; constexpr ll INFL = 1ll << 60; constexpr int dh[4] = { 0,1,0,-1 }; constexpr int dw[4] = { -1,0,1,0 }; bool isin(const int H, const int W, const int h, const int w) { return 0 <= h && h < H && 0 <= w && w < W; } struct ModInt { static const ll MOD = 998244353; // constructors etc ModInt() :num(1ll) {} ModInt(ll num_) :num(num_%MOD) {} ModInt(const ModInt& modint) :num(modint.num%MOD) {} ll get()const { return num; } // operator etc // operator ll() const { return num; } // ll operator*() { return num; } ModInt& operator+=(const ModInt& r) { (num += r.num) %= MOD; return *this; } ModInt& operator-=(const ModInt& r) { (num += -r.num + MOD) %= MOD; return *this; } ModInt& operator*=(const ModInt& r) { (num *= r.num) %= MOD; return *this; } ModInt& operator/=(const ModInt& r) { (num *= r.inv().num) %= MOD; return *this; } ModInt pow(const ModInt& r)const { ll res = 1; ll x = num; ll n = r.num; while (n > 0) { if (n & 1)res = (res*x) % MOD; x = (x*x) % MOD; n >>= 1; } return res; } ModInt inv()const { return this->pow(MOD - 2); } ModInt operator+(const ModInt& r)const { return ModInt(*this) += r; } ModInt operator-(const ModInt& r)const { return ModInt(*this) -= r; } ModInt operator*(const ModInt& r)const { return ModInt(*this) *= r; } ModInt operator/(const ModInt& r)const { return ModInt(*this) /= r; } ModInt operator+(const ll& r)const { return *this + ModInt(r); } ModInt operator-(const ll& r)const { return *this - ModInt(r); } ModInt operator*(const ll& r)const { return *this * ModInt(r); } ModInt operator/(const ll& r)const { return *this / ModInt(r); } private: ll num; }; ostream& operator<<(ostream& stream, const ModInt& val) { stream << val.get(); return stream; } // ============ template finished ============ int main() { int N, Q; cin >> N >> Q; vector<int> A(N), B(Q); rep(i, N)cin >> A[i]; rep(i, Q)cin >> B[i]; vector<ll> now(N + 1, 0), next(N + 1); now[0] = A[0] - 1; now[1] = 1; const ll MOD = 998244353; REP(i, 1, N) { fill(next.begin(), next.end(), 0); next[0] = now[0] * (A[i] - 1) % MOD; REP(j, 1, N + 1) { next[j] = (now[j - 1] + now[j] * (A[i] - 1)) % MOD; } now = next; } for (auto b : B) { cout << now[b] << endl; } return 0; }