結果
問題 | No.1068 #いろいろな色 / Red and Blue and more various colors (Hard) |
ユーザー | toma |
提出日時 | 2020-05-29 22:20:58 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 718 ms / 3,500 ms |
コード長 | 4,324 bytes |
コンパイル時間 | 2,370 ms |
コンパイル使用メモリ | 189,540 KB |
実行使用メモリ | 24,732 KB |
最終ジャッジ日時 | 2024-11-06 05:29:11 |
合計ジャッジ時間 | 16,674 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 17 ms
6,816 KB |
testcase_04 | AC | 13 ms
6,820 KB |
testcase_05 | AC | 15 ms
6,820 KB |
testcase_06 | AC | 12 ms
6,816 KB |
testcase_07 | AC | 10 ms
6,820 KB |
testcase_08 | AC | 14 ms
6,820 KB |
testcase_09 | AC | 15 ms
6,816 KB |
testcase_10 | AC | 8 ms
6,820 KB |
testcase_11 | AC | 11 ms
6,816 KB |
testcase_12 | AC | 6 ms
6,816 KB |
testcase_13 | AC | 709 ms
24,596 KB |
testcase_14 | AC | 717 ms
24,600 KB |
testcase_15 | AC | 715 ms
24,600 KB |
testcase_16 | AC | 718 ms
24,604 KB |
testcase_17 | AC | 712 ms
24,596 KB |
testcase_18 | AC | 712 ms
24,728 KB |
testcase_19 | AC | 713 ms
24,728 KB |
testcase_20 | AC | 708 ms
24,600 KB |
testcase_21 | AC | 707 ms
24,732 KB |
testcase_22 | AC | 716 ms
24,596 KB |
testcase_23 | AC | 712 ms
24,600 KB |
testcase_24 | AC | 709 ms
24,600 KB |
testcase_25 | AC | 718 ms
24,600 KB |
testcase_26 | AC | 718 ms
24,600 KB |
testcase_27 | AC | 703 ms
24,596 KB |
testcase_28 | AC | 712 ms
24,600 KB |
testcase_29 | AC | 652 ms
24,600 KB |
testcase_30 | AC | 658 ms
24,604 KB |
testcase_31 | AC | 2 ms
6,820 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; } //constexpr ll MAX1 = 2001; //constexpr ll MAX2 = MAX1 * MAX1; // tu3 //inline unsigned int __builtin_ctz(unsigned int x) { unsigned long r; _BitScanForward(&r, x); return r; } // ei1333 template< ll mod > struct NumberTheoreticTransform { vector< ll > rev, rts; ll base, max_base, root; NumberTheoreticTransform() : base(1), rev{ 0, 1 }, rts{ 0, 1 } { assert(mod >= 3 && mod % 2 == 1); auto tmp = mod - 1; max_base = 0; while (tmp % 2 == 0) tmp >>= 1, max_base++; root = 2; while (mod_pow(root, (mod - 1) >> 1) == 1) ++root; assert(mod_pow(root, mod - 1) == 1); root = mod_pow(root, (mod - 1) >> max_base); } inline ll mod_pow(ll x, ll n) { ll ret = 1; while (n > 0) { if (n & 1) ret = mul(ret, x); x = mul(x, x); n >>= 1; } return ret; } inline ll inverse(ll x) { return mod_pow(x, mod - 2); } inline unsigned long long add(unsigned long long x, unsigned long long y) { x += y; if (x >= mod) x -= mod; return x; } inline unsigned long long mul(unsigned long long a, unsigned long long b) { return 1ull * a * b % (unsigned long long) mod; } void ensure_base(ll nbase) { if (nbase <= base) return; rev.resize(1 << nbase); rts.resize(1 << nbase); for (ll i = 0; i < (1 << nbase); i++) { rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1)); } assert(nbase <= max_base); while (base < nbase) { ll z = mod_pow(root, 1 << (max_base - 1 - base)); for (ll i = 1 << (base - 1); i < (1 << base); i++) { rts[i << 1] = rts[i]; rts[(i << 1) + 1] = mul(rts[i], z); } ++base; } } void ntt(vector< ll > &a) { const ll n = (ll)a.size(); assert((n & (n - 1)) == 0); ll zeros = __builtin_ctz(n); ensure_base(zeros); ll shift = base - zeros; for (ll i = 0; i < n; i++) { if (i < (rev[i] >> shift)) { swap(a[i], a[rev[i] >> shift]); } } for (ll k = 1; k < n; k <<= 1) { for (ll i = 0; i < n; i += 2 * k) { for (ll j = 0; j < k; j++) { ll z = mul(a[i + j + k], rts[j + k]); a[i + j + k] = add(a[i + j], mod - z); a[i + j] = add(a[i + j], z); } } } } vector< ll > multiply(vector< ll > a, vector< ll > b) { ll need = a.size() + b.size() - 1; ll nbase = 1; while ((1 << nbase) < need) nbase++; ensure_base(nbase); ll sz = 1 << nbase; a.resize(sz, 0); b.resize(sz, 0); ntt(a); ntt(b); ll inv_sz = inverse(sz); for (ll i = 0; i < sz; i++) { a[i] = mul(a[i], mul(b[i], inv_sz)); } reverse(a.begin() + 1, a.end()); ntt(a); a.resize(need); return a; } }; // ============ template finished ============ constexpr ll MOD = 998244353; int main() { ll N, Q; cin >> N >> Q; vector<ll> A(N), B(Q); rep(i, N)cin >> A[i]; rep(i, Q)cin >> B[i]; NumberTheoreticTransform<MOD> ntt; vector<vector<ll>> row(N); rep(i, N)row[i] = { (A[i] - 1) % MOD,1 }; while (row.size() > 1) { vector<vector<ll>> next; rep(i, row.size() / 2) { auto& vl = row[2 * i]; auto& vr = row[2 * i + 1]; next.push_back(ntt.multiply(vl, vr)); } if (row.size() % 2 == 1)next.push_back(row.back()); row = next; } for (auto b : B)cout << row[0][b] << endl; return 0; }