結果
問題 | No.931 Multiplicative Convolution |
ユーザー | pekempey |
提出日時 | 2019-11-23 06:39:01 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,512 bytes |
コンパイル時間 | 2,241 ms |
コンパイル使用メモリ | 183,112 KB |
実行使用メモリ | 12,188 KB |
最終ジャッジ日時 | 2024-10-11 06:46:18 |
合計ジャッジ時間 | 3,659 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
7,520 KB |
testcase_01 | AC | 7 ms
7,324 KB |
testcase_02 | AC | 7 ms
7,392 KB |
testcase_03 | AC | 7 ms
7,312 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 56 ms
12,080 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define repe(i, l, r) for (int i = (l); i < (r); i++) #define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--) #define repi(i, l, r) for (int i = (l); i <= (r); i++) #define repir(i, l, r) for (int i = (r); i >= (l); i--) #define range(a) a.begin(), a.end() void initio() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } constexpr int MOD = 998244353; constexpr int ROOT = 3; class mint { int n; public: mint(int n_ = 0) : n(n_) {} explicit operator int() { return n; } friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); } friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; } friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; } friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; } friend mint &operator+=(mint &a, mint b) { return a = a + b; } friend mint &operator-=(mint &a, mint b) { return a = a - b; } friend mint &operator*=(mint &a, mint b) { return a = a * b; } friend bool operator==(mint a, mint b) { return a.n == b.n; } friend bool operator!=(mint a, mint b) { return a.n != b.n; } friend istream &operator>>(istream &i, mint &a) { return i >> a.n; } friend ostream &operator<<(ostream &o, mint a) { return o << a.n; } }; mint modpow(mint a, long long b) { mint res = 1; while (b > 0) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } mint modinv(mint n) { int a = (int)n, b = MOD; int s = 1, t = 0; while (b != 0) { int q = a / b; a -= q * b; s -= q * t; swap(a, b); swap(s, t); } return s >= 0 ? s : s + MOD; } template<int N> struct NTT { mint rots[N]; NTT() { mint w = modpow(ROOT, (MOD - 1) / N); mint ws = 1; for (int i = 0; i < N / 2; i++) { rots[i + N / 2] = ws; ws *= w; } for (int i = N / 2 - 1; i >= 1; i--) { rots[i] = rots[i * 2]; } } void ntt(vector<mint> &a) { const int n = a.size(); int i = 0; for (int j = 1; j < n - 1; j++) { for (int k = n >> 1; k > (i ^= k); k >>= 1); if (j < i) swap(a[i], a[j]); } for (int i = 1; i < n; i *= 2) { for (int j = 0; j < n; j += i * 2) { for (int k = 0; k < i; k++) { mint s = a[j + k]; mint t = a[j + k + i] * rots[i + k]; a[j + k ] = s + t; a[j + k + i] = s - t; } } } } void invntt(vector<mint> &a) { const int n = a.size(); ntt(a); reverse(a.begin() + 1, a.end()); mint inv_n = modinv(n); for (int i = 0; i < n; i++) { a[i] *= inv_n; } } vector<mint> convolution(vector<mint> a, vector<mint> b) { const int n = a.size() + b.size() - 1; int t = 1; while (t < n) t *= 2; a.resize(t); b.resize(t); ntt(a); ntt(b); for (int i = 0; i < t; i++) { a[i] *= b[i]; } invntt(a); a.resize(n); return a; } }; NTT<1 << 20> ntt; vector<long long> divisors(long long n) { vector<long long> res; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (i * i != n) { res.push_back(n / i); } } } sort(range(res)); return res; } int primitive_root(int p) { auto ds = divisors(p - 1); ds.pop_back(); for (int i = 1; i <= p - 1; i++) { bool all = true; for (int d : ds) { all &= modpow(i, d) != 1; } if (all) return i; } abort(); } int main() { initio(); int P; cin >> P; vector<mint> A(P - 1), B(P - 1); rep(i, P - 1) cin >> A[i]; rep(i, P - 1) cin >> B[i]; int g = primitive_root(P); vector<int> table(P - 1); table[0] = 1; for (int i = 1; i <= P - 2; i++) { table[i] = (ll)table[i - 1] * g % P; } vector<int> inv(P); for (int i = 0; i <= P - 2; i++) { inv[table[i]] = i; } vector<mint> F(P - 1); vector<mint> G(P - 1); for (int i = 0; i <= P - 2; i++) { F[inv[i + 1]] = A[i]; G[inv[i + 1]] = B[i]; } auto ans = ntt.convolution(F, G); for (int i = P - 1; i < ans.size(); i++) { ans[i % (P - 1)] += ans[i]; } vector<mint> true_ans(P); for (int i = 0; i < P - 1; i++) { true_ans[table[i]] = ans[i]; } for (int i = 1; i < true_ans.size(); i++) { cout << true_ans[i] << " \n"[i == true_ans.size() - 1]; } }