結果
問題 | No.1962 Not Divide |
ユーザー | beet |
提出日時 | 2022-05-27 23:19:53 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,297 bytes |
コンパイル時間 | 3,251 ms |
コンパイル使用メモリ | 216,192 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-09-20 16:25:51 |
合計ジャッジ時間 | 20,823 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
7,552 KB |
testcase_01 | AC | 41 ms
7,552 KB |
testcase_02 | AC | 76 ms
7,680 KB |
testcase_03 | WA | - |
testcase_04 | AC | 60 ms
7,552 KB |
testcase_05 | AC | 1,020 ms
7,680 KB |
testcase_06 | WA | - |
testcase_07 | AC | 70 ms
7,680 KB |
testcase_08 | WA | - |
testcase_09 | AC | 980 ms
7,680 KB |
testcase_10 | AC | 108 ms
7,680 KB |
testcase_11 | WA | - |
testcase_12 | AC | 364 ms
7,552 KB |
testcase_13 | AC | 344 ms
7,680 KB |
testcase_14 | WA | - |
testcase_15 | AC | 159 ms
7,552 KB |
testcase_16 | AC | 90 ms
7,680 KB |
testcase_17 | WA | - |
testcase_18 | AC | 5 ms
7,424 KB |
testcase_19 | AC | 5 ms
7,296 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using Int = long long; const char newl = '\n'; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} template<typename T=Int> vector<T> read(size_t n){ vector<T> ts(n); for(size_t i=0;i<n;i++) cin>>ts[i]; return ts; } template<typename T, T MOD = 1000000007> struct Mint{ inline static constexpr T mod = MOD; T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } static Mint add_identity(){return Mint(0);} static Mint mul_identity(){return Mint(1);} Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;} Mint operator-(Mint a) const{return Mint(v)-=a;} Mint operator*(Mint a) const{return Mint(v)*=a;} Mint operator/(Mint a) const{return Mint(v)/=a;} Mint operator+() const{return *this;} Mint operator-() const{return v?Mint(MOD-v):Mint(v);} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} static Mint comb(long long n,Int k){ Mint num(1),dom(1); for(Int i=0;i<k;i++){ num*=Mint(n-i); dom*=Mint(i+1); } return num/dom; } }; template<typename T, T MOD> ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;} // construct a charasteristic equation from sequence // return a monic polynomial in O(n^2) template<typename T> vector<T> berlekamp_massey(vector<T> &as){ using Poly = vector<T>; Int n=as.size(); Poly bs({-T(1)}),cs({-T(1)}); T y(1); for(Int ed=1;ed<=n;ed++){ Int l=cs.size(),m=bs.size(); T x(0); for(Int i=0;i<l;i++) x+=cs[i]*as[ed-l+i]; bs.emplace_back(0); m++; if(x==T(0)) continue; T freq=x/y; if(m<=l){ for(Int i=0;i<m;i++) cs[l-1-i]-=freq*bs[m-1-i]; continue; } auto ts=cs; cs.insert(cs.begin(),m-l,T(0)); for(Int i=0;i<m;i++) cs[m-1-i]-=freq*bs[m-1-i]; bs=ts; y=x; } for(auto &c:cs) c/=cs.back(); return cs; } // O(N M) template<typename T> decltype(auto) naive(){ using Poly = vector<T>; auto conv=[](Poly as, Poly bs){ Poly cs(as.size()+bs.size()-1,0); for(Int i=0;i<(Int)as.size();i++) for(Int j=0;j<(Int)bs.size();j++) cs[i+j]+=as[i]*bs[j]; return cs; }; return +conv; } // Find k-th term of linear recurrence // execute `conv` O(\log k) times template<typename T> struct BostanMori{ using Poly = vector<T>; using Conv = function<Poly(Poly, Poly)>; Conv conv; BostanMori(Conv conv_):conv(conv_){} Poly sub(Poly as,Int odd){ Poly bs((as.size()+!odd)/2); for(Int i=odd;i<(Int)as.size();i+=2) bs[i/2]=as[i]; return bs; } // as: initial values // cs: monic polynomial T build(long long k,Poly as,Poly cs){ reverse(cs.begin(),cs.end()); assert(cs[0]==T(1)); Int n=cs.size()-1; as.resize(n,0); Poly bs=conv(as,cs); bs.resize(n); while(k){ Poly ds(cs); for(Int i=1;i<(Int)ds.size();i+=2) ds[i]=-ds[i]; bs=sub(conv(bs,ds),k&1); cs=sub(conv(cs,ds),0); k>>=1; } return bs[0]; } }; //INSERT ABOVE HERE using M = Mint<Int, 998244353>; const Int N = 5000; M dp[N+1][101]={}; signed main(){ cin.tie(0); ios::sync_with_stdio(0); Int n,m; cin>>n>>m; if(m==1) drop(0); if(m==2) drop(n&1); vector<M> as; dp[0][0]=1; vector<M> acc(m+1,0); for(Int l=0;l<N;l++){ M sum=0; for(Int b=0;b<=m;b++){ dp[l][b]+=acc[b]; sum+=dp[l][b]; } for(Int x=2;x<=m;x++){ acc[x]+=sum-dp[l][x]; for(Int a=x;l+a<=N;a+=x){ dp[l+a][x]-=sum-dp[l][x]; } } if(l>0) as.emplace_back(sum); } BostanMori<M> bm(naive<M>()); cout<<bm.build(n-1,as,berlekamp_massey(as))<<endl; return 0; }