結果
問題 | No.1068 #いろいろな色 / Red and Blue and more various colors (Hard) |
ユーザー | tonyu0 |
提出日時 | 2020-08-01 23:35:50 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,029 bytes |
コンパイル時間 | 9,715 ms |
コンパイル使用メモリ | 371,832 KB |
実行使用メモリ | 40,444 KB |
最終ジャッジ日時 | 2023-09-22 20:31:49 |
合計ジャッジ時間 | 16,460 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | TLE | - |
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 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
ソースコード
#include <algorithm> #include <boost/multiprecision/cpp_int.hpp> #include <complex> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <vector> using namespace std; using namespace boost::multiprecision; using ll = uint128_t; #define rep(i, j, n) for (int i = j; i < (int)n; ++i) constexpr ll MOD = 998244353; namespace fft { using C = complex<long double>; const long double PI = 3.1415926535897932384626433832795028841971; void fft(vector<C>& f, int n, int sgn = 1) { if (n == 1) return; vector<C> f0(n / 2), f1(n / 2); for (int i = 0; i < n / 2; ++i) { f0[i] = f[i * 2]; f1[i] = f[i * 2 + 1]; } fft(f0, n / 2, sgn); fft(f1, n / 2, sgn); C zeta = {cos(2.0 * PI / (long double)n), sin(2.0 * PI / (long double)n) * sgn}; C now = {1.0, 0.0}; for (int i = 0; i < n; ++i) { f[i] = f0[i % (n / 2)] + now * f1[i % (n / 2)]; now *= zeta; } } vector<uint128_t> multiply(vector<uint128_t> a, vector<uint128_t> b) { int n_ = (int)a.size() + (int)b.size() - 1; int n = 1; while (n < (int)a.size() * 2 || n < (int)b.size() * 2) n <<= 1; vector<C> f(n), g(n); for (int i = 0; i < (int)a.size(); ++i) f[i] = {(long double)a[i], 0.0}; for (int i = 0; i < (int)b.size(); ++i) g[i] = {(long double)b[i], 0.0}; fft(f, n); fft(g, n); for (int i = 0; i < n; ++i) f[i] = f[i] * g[i]; // inverse fft(f, n, -1); vector<uint128_t> c(n); for (int i = 0; i < n; ++i) c[i] = (uint128_t)(f[i].real() / (long double)n + 0.5) % MOD; c.resize(n_); return c; } } // namespace fft vector<ll> solve(vector<ll> a) { int n = a.size(); if (n == 1) return {1, a[0] - 1}; vector<ll> f(a.begin(), a.begin() + n / 2); vector<ll> g(a.begin() + n / 2, a.end()); return fft::multiply(solve(f), solve(g)); } int main() { int n, q, b; cin >> n >> q; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; vector<ll> c = solve(a); reverse(c.begin(), c.end()); rep(i, 0, q) { cin >> b; cout << c[b] % MOD << '\n'; } return 0; }