結果
問題 | No.1066 #いろいろな色 / Red and Blue and more various colors (Easy) |
ユーザー | tonyu0 |
提出日時 | 2020-08-01 20:00:56 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,781 bytes |
コンパイル時間 | 882 ms |
コンパイル使用メモリ | 81,260 KB |
実行使用メモリ | 8,760 KB |
最終ジャッジ日時 | 2023-09-22 13:50:21 |
合計ジャッジ時間 | 7,647 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
7,916 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | TLE | - |
testcase_09 | AC | 3 ms
4,380 KB |
testcase_10 | TLE | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
ソースコード
#include <algorithm> #include <iostream> #include <vector> using namespace std; using ll = int64_t; #define rep(i, j, n) for (int i = j; i < (int)n; ++i) constexpr ll MOD = 998244353; int64_t pow(int64_t a, int64_t b) { int64_t x = 1, step = 1 << 30; while (step > 0) { x = x * x % MOD; if (step & b) x = x * a % MOD; step >>= 1; } return x; } void fft(vector<int64_t>& a) { int n = a.size(); for (int i = 0; i < n; i++) { int j = 0; int x = i, y = n - 1; while (y > 0) { j = (j << 1) + (x & 1); x >>= 1; y >>= 1; } if (i < j) swap(a[i], a[j]); } for (int len = 1; len < n; len *= 2) { int64_t root = pow(5, (MOD - 1) / (2 * len)); for (int i = 0; i < n; i += 2 * len) { int64_t w = 1; for (int j = 0; j < len; j++) { int64_t u = a[i + j]; int64_t v = a[i + j + len] * w % MOD; a[i + j] = (u + v) % MOD; a[i + j + len] = (MOD + u - v) % MOD; w = w * root % MOD; } } } } vector<int64_t> multiply(vector<int64_t> a, vector<int64_t> b) { int an = a.size(); int bn = b.size(); int need = an + bn - 1; int nn = 1; while (nn < 2 * an || nn < 2 * bn) nn <<= 1; a.resize(nn); b.resize(nn); fft(a); fft(b); for (int i = 0; i < nn; i++) a[i] = a[i] * b[i] % MOD; reverse(++a.begin(), a.end()); fft(a); int64_t inv = pow(nn, MOD - 2); for (int i = 0; i < nn; i++) a[i] = a[i] * inv % MOD; a.resize(need); return a; } int main() { int n, q, b; cin >> n >> q; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; vector<ll> c(1, 1); rep(i, 0, n) { vector<ll> d = {1, a[i] - 1}; c = multiply(c, d); } reverse(c.begin(), c.end()); rep(i, 0, q) { cin >> b; cout << c[b] << '\n'; } return 0; }