結果

問題 No.1025 Modular Equation
ユーザー tempura_pptempura_pp
提出日時 2020-03-17 00:20:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,787 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 124,144 KB
実行使用メモリ 108,032 KB
最終ジャッジ日時 2023-08-20 19:37:01
合計ジャッジ時間 8,155 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,492 KB
testcase_01 AC 2 ms
5,428 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 AC 24 ms
92,120 KB
testcase_04 AC 20 ms
92,080 KB
testcase_05 AC 27 ms
92,016 KB
testcase_06 WA -
testcase_07 AC 23 ms
108,032 KB
testcase_08 AC 20 ms
95,624 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<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);
    int p,n,k,b;
    cin>>p>>n>>k>>b;
    int m=p-1;
    k = gcd(k,p-1);
    vector<int> 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<int> 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<int> 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]]<<endl;
    cout<<dp[n][par[b]]%mod*powmod((p-1)/k,mod-2,mod)%mod<<endl;
    return 0;
}
0