結果

問題 No.1025 Modular Equation
ユーザー tempura_pptempura_pp
提出日時 2020-03-17 00:23:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,324 ms / 5,000 ms
コード長 1,792 bytes
コンパイル時間 1,216 ms
コンパイル使用メモリ 125,164 KB
実行使用メモリ 392,992 KB
最終ジャッジ日時 2023-08-20 19:37:36
合計ジャッジ時間 25,375 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,488 KB
testcase_01 AC 2 ms
5,440 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 26 ms
108,164 KB
testcase_04 AC 24 ms
108,304 KB
testcase_05 AC 23 ms
108,036 KB
testcase_06 AC 21 ms
99,844 KB
testcase_07 AC 23 ms
107,884 KB
testcase_08 AC 21 ms
95,584 KB
testcase_09 AC 1,259 ms
194,372 KB
testcase_10 AC 1,234 ms
194,528 KB
testcase_11 AC 930 ms
191,908 KB
testcase_12 AC 895 ms
193,812 KB
testcase_13 AC 763 ms
191,388 KB
testcase_14 AC 771 ms
193,388 KB
testcase_15 AC 705 ms
221,992 KB
testcase_16 AC 646 ms
217,064 KB
testcase_17 AC 660 ms
210,516 KB
testcase_18 AC 630 ms
224,468 KB
testcase_19 AC 932 ms
296,700 KB
testcase_20 AC 966 ms
326,088 KB
testcase_21 AC 869 ms
300,932 KB
testcase_22 AC 991 ms
349,728 KB
testcase_23 AC 1,225 ms
383,524 KB
testcase_24 AC 1,324 ms
215,232 KB
testcase_25 AC 1,009 ms
208,512 KB
testcase_26 AC 909 ms
208,268 KB
testcase_27 AC 701 ms
209,188 KB
testcase_28 AC 701 ms
210,244 KB
testcase_29 AC 697 ms
209,092 KB
testcase_30 AC 1,044 ms
331,360 KB
testcase_31 AC 982 ms
303,748 KB
testcase_32 AC 1,295 ms
392,992 KB
testcase_33 AC 83 ms
203,024 KB
testcase_34 AC 154 ms
205,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;


ll powmod(ll n,ll k, ll p){
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%p;
        n=n*n%p;
        k>>=1;
    }
    return ret;
}

ll gcd(ll x,ll y){
    return y?gcd(y,x%y):x;
}

ll dp[501][100001];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll p,n,k,b;
    cin>>p>>n>>k>>b;
    int m=p-1;
    k = gcd(k,p-1);
    vector<ll> div;
    for(int i=2;i<p;i++){
        if(m%i==0){
            div.push_back((p-1)/i);
            while(m%i==0)m/=i;
        }
    }
    int r=-1;
    REP(i,2,p-1){
        bool ok = true;
        for(auto e : div) if(powmod(i,e,p)==1)ok=false;
        if(ok){
            r=i;break;
        }
    }
    vector<ll> c;
    rep(i,(p-1)/k)c.push_back(powmod(r,k*i,p));
    vector<int> par(p,-1);
    rep(i,p){
        if(par[i]!=-1)continue;
        for(auto e:c)par[i*e%p]=i;
    }
    vector<ll> d((p-1)/k);
    rep(i,(p-1)/k)d[i]=powmod(r,k*i,p);
    dp[0][0]=1;
    rep(i,n){
        int x;
        cin>>x;
        rep(j,p){
            if(dp[i][j]==0)continue;
            dp[i][j]%=mod;
            rep(l,(p-1)/k)dp[i+1][par[(j+x*d[l])%p]]+=dp[i][j]*k;
            dp[i+1][j]+=dp[i][j];
        }
    }
    if(b==0)cout<<dp[n][par[b]]%mod<<endl;
    else cout<<dp[n][par[b]]%mod*powmod((p-1)/k,mod-2,mod)%mod<<endl;
    return 0;
}
0