結果
| 問題 |
No.997 Jumping Kangaroo
|
| コンテスト | |
| ユーザー |
tko919
|
| 提出日時 | 2020-03-05 12:38:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 4,543 bytes |
| コンパイル時間 | 1,641 ms |
| コンパイル使用メモリ | 178,976 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-14 00:57:15 |
| 合計ジャッジ時間 | 2,579 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end
template<unsigned mod=1000000007>struct mint {
unsigned val;
static unsigned get_mod(){return mod;}
unsigned inv() const{
int tmp,a=val,b=mod,x=1,y=0;
while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
if(x<0)x+=mod; return x;
}
mint():val(0){}
mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;}
mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;}
mint operator+(const mint& x)const{return mint(*this)+=x;}
mint operator-(const mint& x)const{return mint(*this)-=x;}
mint operator*(const mint& x)const{return mint(*this)*=x;}
mint operator/(const mint& x)const{return mint(*this)/=x;}
bool operator==(const mint& x)const{return val==x.val;}
bool operator!=(const mint& x)const{return val!=x.val;}
};
template<unsigned mod=1000000007>struct factorial {
using Mint=mint<mod>;
vector<Mint> Fact, Finv;
public:
factorial(int maxx){
Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
}
Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};
template<class T>struct mat{
int h,w; vector<vector<T>> val;
mat(){}
mat(int n,int m):h(n),w(m),val(vector<vector<T>>(n,vector<T>(m,0))){}
vector<T>& operator[](const int i){return val[i];}
mat& operator+=(const mat& m){
rep(i,0,h)rep(j,0,w)val[i][j]+=m.val[i][j];
return *this;
}
mat& operator-=(const mat& m){
rep(i,0,h)rep(j,0,w)val[i][j]-=m.val[i][j];
return *this;
}
mat& operator*=(const mat& m){
mat<T> res(h,m.w);
rep(i,0,h)rep(j,0,m.w)rep(k,0,w)res.val[i][j]+=val[i][k]*m.val[k][j];
*this=res; return *this;
}
mat operator+(const mat& m)const{return mat(*this)+=m;}
mat operator-(const mat& m)const{return mat(*this)-=m;}
mat operator*(const mat& m)const{return mat(*this)*=m;}
mat pow(ll k){
mat<T> res(h,h),c=*this; rep(i,0,h)res.val[i][i]=1;
while(k){if(k&1)res*=c; c*=c; k>>=1;} return res;
}
T det(){
assert(h==w); T res=1;
rep(i,0,w){
int idx=-1;
rep(j,i,w)if(val[j][i]!=0)idx=j;
if(idx==-1)return 0;
if(i!=idx)res*=-1; swap(val[i],val[idx]);
res*=val[i][i]; T buf=val[i][i];
rep(j,0,w)val[i][j]/=buf;
rep(j,i+1,w){
T mul=val[j][i];
rep(k,0,w)val[j][k]-=val[i][k]*mul;
}
} return res;
}
vector<int> gauss(int c=-1){
if(val.empty())return {};
if(c==-1)c=val[0].size();
int h=val.size(),w=val[0].size(),r=0;
vector<int> res;
rep(i,0,c){
if(r==h)break;
rep(j,r,h)if(val[j][i]!=0){swap(val[r],val[j]); break;}
if(val[r][i]==0)continue;
rep(j,0,h)if(j!=r){
T buf=val[j][i]/val[r][i];
rep(k,i,w)val[j][k]-=val[r][k]*buf;
} res.push_back(i); r++;
} return res;
}
};
using Mint=mint<>;
int main(){
int n,m; ll k; scanf("%d%d%lld",&n,&m,&k);
vector<int> a(n); rep(i,0,n)scanf("%d",&a[i]);
vector<Mint> dp(2*m+1); dp[0]=1;
rep(i,0,2*m+1)if(i!=m){
rep(j,0,n)if(i+a[j]<=2*m)dp[i+a[j]]+=dp[i];
}
mat<Mint> ma(2,2);
ma[0][0]=dp[m]; ma[0][1]=dp[2*m]; ma[1][0]=1; ma[1][1]=0;
ma=ma.pow(k); printf("%d\n",ma[0][0].val);
return 0;
}
tko919