結果

問題 No.1025 Modular Equation
ユーザー kyort0nkyort0n
提出日時 2020-04-10 22:37:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,129 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 177,088 KB
実行使用メモリ 5,264 KB
最終ジャッジ日時 2023-10-14 01:30:59
合計ジャッジ時間 9,412 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 21 ms
5,264 KB
testcase_03 AC 70 ms
4,356 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 46 ms
4,352 KB
testcase_07 AC 52 ms
4,348 KB
testcase_08 AC 45 ms
4,352 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<ll MOD, ll r>
struct NTT{
	ll zeta[30];
	NTT(){
		int k=0;
		while(!((MOD-1)&(1<<k))) k++;
		zeta[k]=powmod(r, (MOD-1)>>k, MOD);
		for(int i=k-1; i>=0; i--) zeta[i]=zeta[i+1]*zeta[i+1]%MOD;
	}
	vector<ll> fft(vector<ll> a, int k, bool inverse=false){
		int n=a.size();
		vector<ll> tmp(n);
		for(int t=1; t<=k; t++){
			ll w=1, z=zeta[t];
			if(inverse) z=inv(z, MOD);
			for(int i=0; i<n; i++){
				int l=i&((1<<(k-t))-1), h=i&~((1<<(k-t))-1);
				tmp[i]=(a[((h<<1)|l)&(n-1)]+w*a[((h<<1)|l|(1<<(k-t)))&(n-1)])%MOD;
				if((i&((1<<(k-t))-1))==(1<<(k-t))-1) (w*=z)%=MOD;
			}
			swap(a, tmp);
		}
		if(inverse){
			ll invn=inv(n, MOD);
			for(int i=0; i<n; i++) (a[i]*=invn)%=MOD;
		}
		return a;
	}
	vector<ll> multiply(vector<ll> a, vector<ll> b){
		int n=a.size()+b.size()-1, k=0;
		while((1<<k)<n) k++;
		n=(1<<k);
		a.resize(n), b.resize(n);
		a=fft(a, k), b=fft(b, k);
		vector<ll> c(n);
		for(int i=0; i<n; i++) c[i]=a[i]*b[i]%MOD;
		c=fft(c, k, true);
		return c;
	}
};
const ll MOD=1e9+7;
const ll MOD1=167772161;
const ll MOD2=469762049;
const ll MOD3=1224736769;
NTT<MOD1, 3> ntt1;
NTT<MOD2, 3> ntt2;
NTT<MOD3, 3> ntt3;
vector<ll> multiply(vector<ll> a, vector<ll> b){
  /*
  cerr << "--------NTT--------" << endl;
  for(auto val : a) cerr << val << " ";
  cerr << endl;
  for(auto val : b) cerr << val << " ";
  cerr << endl;
  */
	int n=a.size(), m=b.size();
	auto c1=ntt1.multiply(a, b);
	auto c2=ntt2.multiply(a, b);
	auto c3=ntt3.multiply(a, b);
	vector<ll> c(n+m-1);
	ll r2=inv(MOD1, MOD2), r3=inv(MOD1*MOD2%MOD3, MOD3);
	for(int i=0; i<n+m-1; i++){
		ll q2=r2*(c2[i]-c1[i]+MOD2)%MOD2;
		ll q3=r3*(c3[i]-c1[i]+MOD3-q2*MOD1%MOD3+MOD3)%MOD3;
		c[i]=(q3*MOD1%MOD*MOD2+q2*MOD1+c1[i])%MOD;
	}
  /*
  for(auto val : c) cerr << val << " ";
  cerr << endl;
  */
	return c;
}

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<ll> v(p);
    v[0] = 1;
    for(int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        //cerr << i << " " << a << endl;
        vector<ll> 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 = multiply(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;
        */
    }
    cout << v[b] << endl;
    return 0;
}
0