結果
問題 | No.931 Multiplicative Convolution |
ユーザー | kuhaku |
提出日時 | 2020-08-21 01:18:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 532 ms / 2,000 ms |
コード長 | 4,104 bytes |
コンパイル時間 | 2,390 ms |
コンパイル使用メモリ | 214,508 KB |
実行使用メモリ | 9,800 KB |
最終ジャッジ日時 | 2024-10-13 18:10:17 |
合計ジャッジ時間 | 6,358 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 4 ms
5,248 KB |
testcase_07 | AC | 37 ms
5,248 KB |
testcase_08 | AC | 319 ms
9,480 KB |
testcase_09 | AC | 261 ms
9,800 KB |
testcase_10 | AC | 327 ms
9,728 KB |
testcase_11 | AC | 269 ms
9,320 KB |
testcase_12 | AC | 268 ms
8,404 KB |
testcase_13 | AC | 532 ms
9,460 KB |
testcase_14 | AC | 367 ms
9,476 KB |
testcase_15 | AC | 342 ms
9,476 KB |
testcase_16 | AC | 327 ms
9,352 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using Vec = vector<ll>; #define REP(i, m, n) for(ll i = (m); i < (n); ++i) #define rep(i, n) REP(i, 0, n) template <typename T> bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;} template <typename T> bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;} constexpr ll LINF = 1e18L+1; constexpr ll MOD = 998244353; const double PI = acos(-1.0); template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt &operator++() { if((++x) >= mod) x -= mod; return *this; } ModInt operator++(int) { ModInt tmp(*this); operator++(); return tmp; } ModInt &operator--() { if((x += mod - 1) >= mod) x -= mod; return *this; } ModInt operator--(int) { ModInt tmp(*this); operator--(); return tmp; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt res(1), mul(x); while(n > 0) { if(n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; using Mint = ModInt<MOD>; void ntt(vector<Mint> &a, bool inv){ int N = a.size(); int n = 2, d = N / 2; vector<Mint> cp(N); while (n <= N) { for (int p = 0; p < d; ++p) { Mint omega = Mint(3).pow((MOD - 1) / n); if (inv) omega = omega.inverse(); Mint pow_omega = 1; for (int i = 0; i < n / 2; ++i) { cp[p + d * i] = a[p + 2 * d * i] + pow_omega * a[p + 2 * d * i + d]; cp[p + d * i + N / 2] = a[p + 2 * d * i] - pow_omega * a[p + 2 * d * i + d]; pow_omega *= omega; } } for (int i = 0; i < N; ++i) a[i] = cp[i]; n <<= 1, d >>= 1; } } void conv(vector<Mint> &a, vector<Mint> b){ int n = a.size() + b.size(); int N = 1; while (N <= n) N <<= 1; a.resize(N); b.resize(N); ntt(a, false); ntt(b, false); for (int i = 0; i < N; ++i) { a[i] *= b[i] / N; } ntt(a, true); } ll find_root(ll p){ for(ll i = 2; i < p; ++i){ unordered_set<ll> used; ll t = 1; bool flg = true; for(ll j = 0; j < p - 2; ++j){ used.insert(t); (t *= i) %= p; if(used.find(t) != used.end()) { flg = false; break; } } if(flg) return i; } return 0; } int main(void) { ll p; cin >> p; Vec a(p), b(p); rep(i, p - 1) cin >> a[i + 1]; rep(i, p - 1) cin >> b[i + 1]; ll r = find_root(p); cerr << r << endl; ll t = 1; vector<Mint> u(p), v(p); rep(i, p - 1){ v[i] = a[t]; u[i] = b[t]; (t *= r) %= p; } conv(v, u); t = 1; vector<Mint> ans(p); rep(i, v.size()){ // cerr << v[i] << endl; ans[t] += v[i]; (t *= r) %= p; } rep(i, p - 1) cout << ans[i + 1] << " "; cout << endl; return 0; }