結果
問題 | No.1731 Product of Subsequence |
ユーザー | ytqm3 |
提出日時 | 2021-11-20 12:22:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,456 bytes |
コンパイル時間 | 2,304 ms |
コンパイル使用メモリ | 221,728 KB |
実行使用メモリ | 64,512 KB |
最終ジャッジ日時 | 2024-06-11 04:50:48 |
合計ジャッジ時間 | 8,518 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 319 ms
63,052 KB |
testcase_01 | AC | 39 ms
50,084 KB |
testcase_02 | AC | 40 ms
50,152 KB |
testcase_03 | AC | 39 ms
50,100 KB |
testcase_04 | AC | 40 ms
50,156 KB |
testcase_05 | AC | 41 ms
50,072 KB |
testcase_06 | AC | 41 ms
50,164 KB |
testcase_07 | AC | 40 ms
50,192 KB |
testcase_08 | AC | 189 ms
64,384 KB |
testcase_09 | WA | - |
testcase_10 | AC | 393 ms
64,384 KB |
testcase_11 | AC | 309 ms
60,692 KB |
testcase_12 | AC | 42 ms
50,176 KB |
testcase_13 | AC | 42 ms
50,256 KB |
testcase_14 | AC | 267 ms
58,492 KB |
testcase_15 | AC | 39 ms
50,092 KB |
testcase_16 | WA | - |
testcase_17 | AC | 39 ms
50,048 KB |
testcase_18 | AC | 391 ms
64,384 KB |
testcase_19 | AC | 43 ms
50,084 KB |
testcase_20 | AC | 291 ms
59,312 KB |
testcase_21 | AC | 379 ms
64,396 KB |
testcase_22 | AC | 315 ms
64,364 KB |
testcase_23 | WA | - |
testcase_24 | AC | 42 ms
50,128 KB |
testcase_25 | AC | 42 ms
50,072 KB |
testcase_26 | AC | 61 ms
50,532 KB |
testcase_27 | AC | 72 ms
51,000 KB |
testcase_28 | AC | 143 ms
53,408 KB |
testcase_29 | AC | 64 ms
50,600 KB |
testcase_30 | AC | 350 ms
64,460 KB |
testcase_31 | AC | 303 ms
64,512 KB |
testcase_32 | WA | - |
testcase_33 | AC | 47 ms
50,228 KB |
testcase_34 | AC | 46 ms
50,164 KB |
ソースコード
#include<bits/stdc++.h> typedef uint64_t u64; typedef int64_t i64; using namespace std; void solve(); int main(){ cout<<fixed<<setprecision(15); bool is_multicase=false; int T=1; if(is_multicase){ cin>>T; } for(int i=0;i<T;++i){ solve(); } return 0; } template<typename T> void turtle_in(T& n){ cin>>n; } template<typename T,typename U> void turtle_in(pair<T,U>& p){ turtle_in(p.first); turtle_in(p.second); } template<typename T> void turtle_in(vector<T>& v){ for(auto& u:v){ turtle_in(u); } } template<typename T> void turtle_out(T& n){ cout<<n; } template<typename T,typename U> void turtle_out(pair<T,U>& p){ cout<<"{"; turtle_out(p.first); cout<<", "; turtle_out(p.second); cout<<"}"; } template<typename T> void turtle_out(vector<T>& v){ for(int i=0;i<int(v.size());++i){ turtle_out(v[i]); if(i!=v.size()-1){ cout<<" "; } } cout<<endl; } template<typename T> void turtle_out(vector<vector<T>>& v){ for(int i=0;i<int(v.size());++i){ turtle_out(v[i]); } } void scan(){} template<typename T,class... Args> void scan(T& n,Args&... args){ turtle_in(n); scan(args...); } void print(){} template<typename T,class... Args> void print(T n,Args... args){ turtle_out(n); print(args...); } template<typename T> void println(T n){ turtle_out(n); cout<<endl; } template<typename T,class... Args> void println(T n,Args... args){ turtle_out(n); cout<<" "; println(args...); } template<u64 mod> struct modint{ u64 val; modint(i64 val_=0):val((val_%i64(mod)+i64(mod))%i64(mod)){} modint operator-(){ return modint(mod-val); } modint operator+(modint rhs){ return modint(*this)+=rhs; } modint operator-(modint rhs){ return modint(*this)-=rhs; } modint operator*(modint rhs){ return modint(*this)*=rhs; } modint operator/(modint rhs){ return modint(*this)/=rhs; } modint &operator+=(modint rhs){ val+=rhs.val; val-=((val>=mod)?mod:0); return (*this); } modint &operator-=(modint rhs){ val+=((val<rhs.val)?mod:0); val-=rhs.val; return (*this); } modint &operator*=(modint rhs){ val=val*rhs.val%mod; return (*this); } modint &operator/=(modint rhs){ u64 ex=mod-2; modint now=1; while(ex){ now*=((ex&1)?rhs:1); rhs*=rhs,ex>>=1; } return (*this)*=now; } bool operator==(modint rhs){ return val==rhs.val; } bool operator!=(modint rhs){ return val!=rhs.val; } friend std::ostream &operator<<(std::ostream& os,modint x){ return os<<(x.val); } friend std::istream &operator>>(std::istream& is,modint& x){ u64 t; is>>t,x=t; return is; } }; template<typename T,typename U> T power(T a,U n){ T res=1; while(n>0){ if(n%2==1){ res*=a; } a*=a; n/=2; } return res; } template<typename T> struct genrand{ uniform_int_distribution<T> gen; mt19937 engine; genrand(T a,T b):gen(a,b){ random_device seed_gen; engine.seed(seed_gen()); } T operator()(){ return gen(engine); } }; template<typename T> struct comb{ vector<T> dat,idat; comb(int mx=3000000):dat(mx+1,1),idat(mx+1,1){ for(int i=1;i<=mx;++i){ dat[i]=dat[i-1]*i; } idat[mx]/=dat[mx]; for(int i=mx;i>0;--i){ idat[i-1]=idat[i]*i; } } T operator()(int n,int k){ if(n<0||k<0||n<k){ return 0; } return dat[n]*idat[k]*idat[n-k]; } }; template<typename T> struct matrix{ vector<vector<T>> val; int height,width; matrix(int H,int W,T init=0):val(H,vector<T> (W,init)),height(H),width(W){} vector<T> &operator[](int i){ return val[i]; } matrix operator+(matrix rhs){ return matrix(*this)+=rhs; } matrix operator*(matrix rhs){ return matrix(*this)*=rhs; } matrix operator+=(matrix rhs){ for(int i=0;i<rhs.height;++i){ for(int j=0;j<rhs.width;++j){ (*this)[i][j]+=rhs[i][j]; } } return (*this); } matrix operator*=(matrix rhs){ matrix<T> res(height,rhs.width,0); for(int i=0;i<this->height;++i){ for(int j=0;j<rhs.width;++j){ for(int k=0;k<this->width;++k){ res[i][j]+=(*this)[i][k]*rhs[k][j]; } } } return (*this)=res; } matrix identity(int n){ matrix res(n,n); for(int i=0;i<n;++i){ res[i][i]=1; } return res; } matrix mat_pow(i64 k){ int n=(*this).height; matrix res=identity(n),now=(*this); while(k>0){ if(k%2==1){ res*=now; } now*=now; k/=2; } return (*this)=res; } }; vector<i64> enum_divs(i64 n){ vector<i64> res; for(i64 i=1;i*i<=n;++i){ if(n%i==0){ res.emplace_back(i); if(i*i!=n){ res.emplace_back(n/i); } } } sort(res.begin(),res.end()); return res; } void solve(){ constexpr u64 mod=1000000007; typedef modint<mod> mint; i64 N,K; scan(N,K); vector<i64> A(N); scan(A); vector<i64> divs=enum_divs(K); map<i64,i64> mp; i64 M=divs.size(); for(int i=0;i<M;++i){ mp[divs[i]]=i; } vector<i64> cnt(M); for(auto v:A){ cnt[mp[gcd(v,K)]]++; } vector<vector<mint>> dp(M+1,vector<mint> (M)); comb<mint> C; dp[0][0]=1; for(int i=0;i<M;++i){ i64 now=1; for(int j=0;j<=cnt[i];++j){ for(int k=0;k<M;++k){ dp[i+1][mp[gcd(divs[k]*now,K)]]+=dp[i][k]*C(cnt[i],j); } now=gcd(now*divs[i],K); } } println(dp[M][M-1]); }