結果

問題 No.1025 Modular Equation
ユーザー sbitesbite
提出日時 2020-04-10 22:33:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 3,186 bytes
コンパイル時間 2,543 ms
コンパイル使用メモリ 208,116 KB
実行使用メモリ 602,792 KB
最終ジャッジ日時 2023-10-14 01:19:38
合計ジャッジ時間 15,506 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const double EPS = 1e-3;
const double PI = 3.1415926535897932384626433832795028841971;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

VVL nums(330, VL(101010, {}));
ll p, n, k, b;
VL v(101010);

void fft(vector<complex<long double>> &v)
{
    int n = (int)v.size();
    if (n <= 1)
        return;
    int half = n / 2;
    vector<complex<long double>> even(half), odd(half);
    //assert(half * 2 == n);

    complex<long double> w = polar((lld)1.0, -2.0 * PI / (long double)n);
    long double arg = -2.0 * PI / (long double)n;
    for (int i = 0; i < half; i++)
    {
        even[i] = v[i] + v[half + i];
        auto tmp = (v[i] - v[half + i]); // * pow(w, i);
        long double wr = cos(arg * i);
        long double wi = sin(arg * i);

        odd[i].real(tmp.real() * wr - tmp.imag() * wi);
        odd[i].imag(tmp.real() * wi + tmp.imag() * wr);
    }
    fft(even);
    fft(odd);
    for (int i = 0; i < half; i++)
    {
        v[2 * i] = even[i];
        v[2 * i + 1] = odd[i];
    }
}

void ifft(vector<complex<long double>> &v)
{
    int n = (int)v.size();
    for (auto &x : v)
        x = conj(x);
    fft(v);
    for (auto &x : v)
        x = conj(x) / (long double)n;
}

int pow2_at_least(int n)
{
    int ret = 1;
    while (ret < n)
        ret *= 2;
    return ret;
}

vector<ll> convolution(vector<ll> &a, vector<ll> &b)
{
    int n = pow2_at_least(2 * (int)max(a.size(), b.size()) + 1);
    vector<complex<long double>> x(n, (0, 0)), y(n, (0, 0));
    vector<ll> c(n, 0);
    rep(i, a.size())
    {
        x[i].real(a[i]);
    }
    rep(i, b.size())
    {
        y[i].real(b[i]);
    }
    fft(x);
    fft(y);
    rep(i, n)
    {
        y[i] = x[i] * y[i];
    }
    ifft(y);
    rep(i, n)
    {
        c[i] = round(y[i].real());
    }
    return c;
}

ll pmod(ll base, ll n)
{
    if (n == 0)
        return 1;
    ll prev = pmod(base, n / 2);
    if (n % 2 == 0)
    {
        return (prev * prev) % p;
    }
    else
    {
        return (prev * prev * base) % p;
    }
}

int main()
{
    cin >> p >> n >> k >> b;
    rep(i, n) cin >> v[i];
    ll tmp;
    rep(i, n)
    {
        rep(j, p)
        {
            tmp = pmod(j, k);
            tmp = (tmp * v[i]) % p;
            nums[i][tmp]++;
        }
    }
    VL ans = nums[0];
    //cerr << "calc" << endl;
    rep(i, 1, n)
    {
        VL nans = convolution(ans, nums[i]);
        rep(j, p)
        {
            ans[j] = 0;
        }
        rep(j, nans.size())
        {
            ans[j % p] += nans[j] % MOD;
            ans[j % p] %= MOD;
        }
    }
    cout << ans[b] << endl;
    return 0;
}
0