結果

問題 No.137 貯金箱の焦り
ユーザー 👑 kmjpkmjp
提出日時 2015-01-26 00:02:46
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,689 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 147,572 KB
実行使用メモリ 17,492 KB
最終ジャッジ日時 2023-09-05 06:46:51
合計ジャッジ時間 8,231 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,776 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,M;
ll A[55],B[55];
ll mo=1234567891LL;

ll pat[501][501];

const int MAT=502;
ll G[MAT][MAT],G2[MAT][MAT];

void powmat(ll p,int n,ll a[MAT][MAT],ll r[MAT][MAT]) {
	int i,x,y,z;
	static ll a2[MAT][MAT];
	FOR(x,n) FOR(y,n) a2[x][y]=a[x][y];
	FOR(x,n) FOR(y,n) r[x][y]=0;
	FOR(i,n) r[i][i]=1;
	while(p) {
		static  ll h[MAT][MAT];
		ZERO(h);
		if(p%2) {
			FOR(x,n) FOR(y,n) h[x][y]=0;
			FOR(x,n) FOR(z,n) FOR(y,n) h[x][y] += (r[x][z]*a2[z][y]) % mo;
			FOR(x,n) FOR(y,n) r[x][y]=h[x][y]%mo;
		}
		FOR(x,n) FOR(y,n) h[x][y]=0;
		FOR(x,n) FOR(z,n) FOR(y,n) h[x][y] += (a2[x][z]*a2[z][y]) % mo;
		FOR(x,n) FOR(y,n) a2[x][y]=h[x][y]%mo;
		p>>=1;
	}
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) cin>>A[i];
	pat[0][0]=1;
	FOR(i,N) {
		for(j=0;j*A[i]<=500;j++) {
			for(x=0;x+j*A[i]<=500;x++) pat[i+1][x+j*A[i]]=(pat[i+1][x+j*A[i]]+pat[i][x])%mo;
		}
	}
	
	if(M<=500) return _P("%lld\n",pat[N][M]);
	FOR(i,N) G[0][500-A[i]]=1;
	FOR(x,499) G[x+1][x]=1;
	
	powmat(M-500,500,G,G2);
	ll ret=0;
	FOR(x,500) ret+=G2[0][x]*pat[N][500-x]%mo;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0