結果

問題 No.1025 Modular Equation
ユーザー chocoruskchocorusk
提出日時 2020-04-07 15:15:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 622 ms / 5,000 ms
コード長 1,263 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 76,404 KB
実行使用メモリ 6,816 KB
最終ジャッジ日時 2023-09-21 20:06:13
合計ジャッジ時間 10,629 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 334 ms
5,612 KB
testcase_10 AC 344 ms
5,964 KB
testcase_11 AC 260 ms
5,764 KB
testcase_12 AC 262 ms
5,816 KB
testcase_13 AC 229 ms
5,740 KB
testcase_14 AC 238 ms
5,752 KB
testcase_15 AC 234 ms
5,756 KB
testcase_16 AC 222 ms
5,672 KB
testcase_17 AC 232 ms
5,600 KB
testcase_18 AC 217 ms
5,400 KB
testcase_19 AC 300 ms
6,260 KB
testcase_20 AC 279 ms
5,880 KB
testcase_21 AC 289 ms
5,992 KB
testcase_22 AC 291 ms
5,912 KB
testcase_23 AC 576 ms
6,412 KB
testcase_24 AC 374 ms
5,908 KB
testcase_25 AC 279 ms
5,768 KB
testcase_26 AC 265 ms
5,816 KB
testcase_27 AC 252 ms
5,680 KB
testcase_28 AC 244 ms
5,620 KB
testcase_29 AC 242 ms
5,756 KB
testcase_30 AC 301 ms
5,912 KB
testcase_31 AC 331 ms
6,128 KB
testcase_32 AC 622 ms
6,816 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 235 ms
5,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll MOD=1e9+7;
ll powmod(ll a, ll k, ll mod){
	if(a==0) return 0;
    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);
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b, a%b);
}
int main()
{
    int n, k; ll b, p;
	cin>>p>>n>>k>>b;
	vector<ll> a(n);
	k=gcd(k, p-1);
	for(int i=0; i<n; i++) cin>>a[i];
	ll r;
	for(r=1; r<p; r++){
		bool dame=0;
		ll pp=1;
		for(int i=0; i<p-2; i++){
			(pp*=r)%=p;
			if(pp==1){
				dame=1; break;
			}
		}
		if(!dame) break;
	}
	vector<ll> q(p-1);
	vector<int> qi(p);
	q[0]=1;
	for(int i=1; i<p-1; i++) q[i]=q[i-1]*r%p;
	for(int i=0; i<p-1; i++) qi[q[i]]=i%k;
	vector<ll> dp(p);
	dp[0]=1;
	for(int i=0; i<n; i++){
	    vector<ll> tmp=dp;
		vector<ll> s(k);
		for(int j=0; j<p; j++){
			int x=j+a[i];
			if(x>=p) x-=p;
			if(x==0) (tmp[0]+=dp[j]*(p-1))%=MOD;
			else (s[qi[x]]+=dp[j]*k)%=MOD;
		}
		for(int j=1; j<p; j++){
			tmp[j]+=s[qi[j]];
			if(tmp[j]>=MOD) tmp[j]-=MOD;
		}
		swap(tmp, dp);
	}
	cout<<dp[b]<<endl;
    return 0;
}
0