結果
問題 | No.1521 Playing Musical Chairs Alone |
ユーザー |
|
提出日時 | 2021-05-28 20:44:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 106 ms / 2,000 ms |
コード長 | 2,976 bytes |
コンパイル時間 | 1,003 ms |
コンパイル使用メモリ | 76,832 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 08:18:43 |
合計ジャッジ時間 | 2,882 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
コンパイルメッセージ
a.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
ソースコード
#line 1 "a.cpp" #include<iostream> #include<atcoder/modint> using namespace std; using mint=atcoder::modint1000000007; #line 1 "/home/kotatsugame/library/math/matrix.cpp" #include<vector> #include<cassert> template<typename T> struct Matrix{ vector<vector<T> >dat; int N,M;//N x M matrix Matrix(){} Matrix(int N_):Matrix(N_,N_){} Matrix(int N_,int M_):N(N_),M(M_),dat(N_,vector<T>(M_)){} vector<T>&operator[](int i){return dat[i];} const vector<T>&operator[](int i)const{return dat[i];} static Matrix eye(int N) { Matrix res(N); for(int i=0;i<N;i++)res[i][i]=1; return res; } Matrix operator+(const Matrix&A)const { assert(N==A.N&&M==A.M); Matrix res(N,M); for(int i=0;i<N;i++)for(int j=0;j<M;j++) res[i][j]=dat[i][j]+A[i][j]; return res; } Matrix operator-(const Matrix&A)const { assert(N==A.N&&M==A.M); Matrix res(N,M); for(int i=0;i<N;i++)for(int j=0;j<M;j++) res[i][j]=dat[i][j]-A[i][j]; return res; } Matrix operator*(const Matrix&A)const { assert(M==A.N); Matrix res(N,A.M); for(int i=0;i<N;i++)for(int j=0;j<A.M;j++)for(int k=0;k<M;k++) res[i][j]+=dat[i][k]*A[k][j]; return res; } Matrix pow(long long n)const { assert(N==M); Matrix a=*this,res=eye(N); for(;n;a=a*a,n>>=1)if(n&1)res=res*a; return res; } template<typename U> Matrix operator+(const U&A)const { Matrix res(N,M); for(int i=0;i<N;i++)for(int j=0;j<M;j++) res[i][j]=dat[i][j]+A; return res; } template<typename U> Matrix operator-(const U&A)const { Matrix res(N,M); for(int i=0;i<N;i++)for(int j=0;j<M;j++) res[i][j]=dat[i][j]-A; return res; } template<typename U> Matrix operator*(const U&A)const { Matrix res(N,M); for(int i=0;i<N;i++)for(int j=0;j<M;j++) res[i][j]=dat[i][j]*A; return res; } T det()const { assert(N==M); Matrix A=*this; T ret=1; for(int j=0;j<N;j++) { int id=-1; for(int i=j;i<N;i++) { if(A[i][j]!=0) { id=i; break; } } if(id==-1)return T(0); if(id!=j) { A[j].swap(A[id]); ret=-ret; } ret*=A[j][j]; { const T a=1/A[j][j]; for(int k=j+1;k<N;k++)A[j][k]*=a; } for(int i=j+1;i<N;i++) { const T a=A[i][j]; for(int k=j+1;k<N;k++)A[i][k]-=A[j][k]*a; } } return ret; } int elimination() { int ret=0; for(int j=0;j<M;j++) { int id=-1; for(int i=ret;i<N;i++) { if(dat[i][j]!=0) { id=i; break; } } if(id==-1)continue; if(id!=ret)dat[ret].swap(dat[id]); { const T a=1/dat[ret][j]; for(int k=j;k<M;k++)dat[ret][k]*=a; } for(int i=0;i<N;i++) { if(i==ret)continue; const T a=dat[i][j]; for(int k=j;k<M;k++)dat[i][k]-=dat[ret][k]*a; } ret++; } return ret; } }; #line 6 "a.cpp" using mat=Matrix<mint>; int N,K,L; main() { cin>>N>>K>>L; mat A(N,N); for(int i=0;i<N;i++)for(int j=1;j<=L;j++)A[(i+j)%N][i]++; mat B(N,1); B[0][0]=1; A=A.pow(K)*B; for(int i=0;i<N;i++)cout<<A[i][0].val()<<endl; }