結果
問題 | No.1025 Modular Equation |
ユーザー | kyort0n |
提出日時 | 2020-04-10 22:56:45 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 6,637 bytes |
コンパイル時間 | 2,770 ms |
コンパイル使用メモリ | 201,500 KB |
実行使用メモリ | 19,564 KB |
最終ジャッジ日時 | 2024-09-15 23:21:29 |
合計ジャッジ時間 | 9,525 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 12 ms
5,376 KB |
testcase_03 | AC | 36 ms
5,376 KB |
testcase_04 | AC | 36 ms
5,376 KB |
testcase_05 | AC | 33 ms
5,376 KB |
testcase_06 | AC | 23 ms
5,376 KB |
testcase_07 | AC | 26 ms
5,376 KB |
testcase_08 | AC | 23 ms
5,376 KB |
testcase_09 | TLE | - |
testcase_10 | -- | - |
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 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const long double EPS = 1e-10; const long long INF = 1e18; const long double PI = acos(-1.0L); //const ll mod = 1000000007; #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; ll powmod(ll a, ll k, ll mod){ ll ap=a, ans=1; while(k){ if(k&1){ ans*=ap; ans%=mod; } ap=ap*ap; ap%=mod; k>>=1; } return ans; } ll inv(ll a, ll mod){ return powmod(a, mod-2, mod); } template <class Z> Z getint() { char c = getchar(); bool neg = c == '-'; Z res = neg ? 0 : c - '0'; while (isdigit(c = getchar())) res = res * 10 + (c - '0'); return neg ? -res : res; } template <class Z> void putint(Z a, char c = '\n') { if (a < 0) putchar('-'), a = -a; int d[40], i = 0; do d[i++] = a % 10; while (a /= 10); while (i--) putchar('0' + d[i]); putchar(c); } template <class T, class F = multiplies<T>> T power(T a, long long n, F op = multiplies<T>(), T e = {1}) { assert(n >= 0); T res = e; while (n) { if (n & 1) res = op(res, a); if (n >>= 1) a = op(a, a); } return res; } template <unsigned Mod> struct Modular { using M = Modular; unsigned v; Modular(long long a = 0) : v((a %= Mod) < 0 ? a + Mod : a) {} M operator-() const { return M() -= *this; } M& operator+=(M r) { if ((v += r.v) >= Mod) v -= Mod; return *this; } M& operator-=(M r) { if ((v += Mod - r.v) >= Mod) v -= Mod; return *this; } M& operator*=(M r) { v = (uint64_t)v * r.v % Mod; return *this; } M& operator/=(M r) { return *this *= power(r, Mod - 2); } friend M operator+(M l, M r) { return l += r; } friend M operator-(M l, M r) { return l -= r; } friend M operator*(M l, M r) { return l *= r; } friend M operator/(M l, M r) { return l /= r; } friend bool operator==(M l, M r) { return l.v == r.v; } }; template <unsigned Mod> void ntt(vector<Modular<Mod>>& a, bool inverse) { static vector<Modular<Mod>> dw(30), idw(30); if (dw[0] == 0) { Modular<Mod> root = 2; while (power(root, (Mod - 1) / 2) == 1) root += 1; for (int i = 0; i < 30; ++i) dw[i] = -power(root, (Mod - 1) >> (i + 2)), idw[i] = 1 / dw[i]; } int n = a.size(); assert((n & (n - 1)) == 0); if (not inverse) { for (int m = n; m >>= 1; ) { Modular<Mod> w = 1; for (int s = 0, k = 0; s < n; s += 2 * m) { for (int i = s, j = s + m; i < s + m; ++i, ++j) { auto x = a[i], y = a[j] * w; if (x.v >= Mod) x.v -= Mod; a[i].v = x.v + y.v, a[j].v = x.v + (Mod - y.v); } w *= dw[__builtin_ctz(++k)]; } } } else { for (int m = 1; m < n; m *= 2) { Modular<Mod> w = 1; for (int s = 0, k = 0; s < n; s += 2 * m) { for (int i = s, j = s + m; i < s + m; ++i, ++j) { auto x = a[i], y = a[j]; a[i] = x + y, a[j].v = x.v + (Mod - y.v), a[j] *= w; } w *= idw[__builtin_ctz(++k)]; } } } auto c = 1 / Modular<Mod>(inverse ? n : 1); for (auto&& e : a) e *= c; } template <unsigned Mod> vector<Modular<Mod>> operator*(vector<Modular<Mod>> l, vector<Modular<Mod>> r) { if (l.empty() or r.empty()) return {}; int n = l.size(), m = r.size(), sz = 1 << __lg(2 * (n + m - 1) - 1); if (min(n, m) < 30) { vector<long long> res(n + m - 1); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) res[i + j] += (l[i] * r[j]).v; return {begin(res), end(res)}; } bool eq = l == r; l.resize(sz), ntt(l, false); if (eq) r = l; else r.resize(sz), ntt(r, false); for (int i = 0; i < sz; ++i) l[i] *= r[i]; ntt(l, true), l.resize(n + m - 1); return l; } constexpr long long mod = 1e9 + 7; using Mint = Modular<mod>; vector<Mint> operator*(const vector<Mint>& l, const vector<Mint>& r) { if (l.empty() or r.empty()) return {}; int n = l.size(), m = r.size(); static constexpr int mod0 = 998244353, mod1 = 1300234241, mod2 = 1484783617; using Mint0 = Modular<mod0>; using Mint1 = Modular<mod1>; using Mint2 = Modular<mod2>; vector<Mint0> l0(n), r0(m); vector<Mint1> l1(n), r1(m); vector<Mint2> l2(n), r2(m); for (int i = 0; i < n; ++i) l0[i] = l[i].v, l1[i] = l[i].v, l2[i] = l[i].v; for (int j = 0; j < m; ++j) r0[j] = r[j].v, r1[j] = r[j].v, r2[j] = r[j].v; l0 = l0 * r0, l1 = l1 * r1, l2 = l2 * r2; vector<Mint> res(n + m - 1); static const Mint1 im0 = 1 / Mint1(mod0); static const Mint2 im1 = 1 / Mint2(mod1), im0m1 = im1 / mod0; static const Mint m0 = mod0, m0m1 = m0 * mod1; for (int i = 0; i < n + m - 1; ++i) { int y0 = l0[i].v; int y1 = (im0 * (l1[i] - y0)).v; int y2 = (im0m1 * (l2[i] - y0) - im1 * y1).v; res[i] = y0 + m0 * y1 + m0m1 * y2; } return res; } using Mint = Modular<mod>; int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); ll p, n, k, b; cin >> p >> n >> k >> b; vector<ll> x(p); for(int i = 0; i < p; i++) { x[i] = powmod(i, k, p); } vector<Mint> v(p); v[0] = 1; for(int i = 0; i < n; i++) { ll a; cin >> a; //cerr << i << " " << a << endl; vector<Mint> w(p); for(ll i = 0; i < p; i++) { w[x[i] * a % p] += 1; } /* cerr << "w: "; for(int i = 0; i < p; i++) { cerr << w[i] << " "; } cerr << endl; */ v = v * w; /* for(auto val : v) { cerr << val << " "; } cerr << endl; */ for(int i = p; i < v.size(); i++) { v[i-p] += v[i]; } v.resize(p); /* for(auto val : v) { cerr << val << " "; } cerr << endl; */ } ll ans = v[b].v; cout << ans << endl; //cout << v[b] << endl; return 0; }