結果

問題 No.288 貯金箱の仕事
ユーザー 👑 kmjpkmjp
提出日時 2015-10-09 22:57:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,820 ms / 2,000 ms
コード長 1,191 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 146,228 KB
実行使用メモリ 6,008 KB
最終ジャッジ日時 2023-09-27 10:15:22
合計ジャッジ時間 32,084 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 196 ms
6,008 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 156 ms
5,772 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 71 ms
5,732 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 125 ms
5,992 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 181 ms
5,856 KB
testcase_16 AC 153 ms
5,852 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 84 ms
5,732 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 72 ms
5,852 KB
testcase_22 AC 147 ms
5,780 KB
testcase_23 AC 1,793 ms
5,728 KB
testcase_24 AC 910 ms
5,716 KB
testcase_25 AC 10 ms
5,512 KB
testcase_26 AC 10 ms
5,324 KB
testcase_27 AC 9 ms
5,332 KB
testcase_28 AC 9 ms
5,332 KB
testcase_29 AC 11 ms
5,972 KB
testcase_30 AC 501 ms
6,008 KB
testcase_31 AC 474 ms
5,736 KB
testcase_32 AC 909 ms
5,884 KB
testcase_33 AC 915 ms
5,728 KB
testcase_34 AC 1,370 ms
5,776 KB
testcase_35 AC 1,363 ms
5,772 KB
testcase_36 AC 1,820 ms
5,716 KB
testcase_37 AC 524 ms
5,780 KB
testcase_38 AC 1,257 ms
5,848 KB
testcase_39 AC 605 ms
5,716 KB
testcase_40 AC 621 ms
5,920 KB
testcase_41 AC 1,717 ms
5,780 KB
testcase_42 AC 1,517 ms
5,784 KB
testcase_43 AC 175 ms
4,380 KB
testcase_44 AC 743 ms
5,772 KB
testcase_45 AC 1,383 ms
5,732 KB
testcase_46 AC 1,523 ms
5,840 KB
testcase_47 AC 1,018 ms
6,008 KB
testcase_48 AC 1,095 ms
5,776 KB
testcase_49 AC 342 ms
4,836 KB
testcase_50 AC 882 ms
5,908 KB
testcase_51 AC 654 ms
5,724 KB
testcase_52 AC 895 ms
5,728 KB
testcase_53 AC 1,169 ms
5,852 KB
testcase_54 AC 824 ms
5,724 KB
testcase_55 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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 FORR(x,arr) for(auto& x:arr)
#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))
//-------------------------------------------------------

int N;
ll M;
int A[501];
ll K[501];
ll can[400000];
int ok[501];
int G;
ll tot;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) cin>>A[i], ok[A[i]]=1;
	FOR(i,N) cin>>K[i], tot += K[i]*A[i];
	if(tot<M) return _P("-1\n");
	M=tot-M;
	
	FOR(i,min(M+1,300001LL)) can[i]=1LL<<60;
	can[0]=0;
	
	ll ret=1LL<<60;
	FOR(i,min(M+1,300001LL)) {
		FOR(x,N) if(i+A[x]<=300000) can[i+A[x]] = min(can[i+A[x]], can[i]+1);
		FOR(x,N) if(M>=i && (M-i)%A[x]==0) ret=min(ret,can[i]+(M-i)/A[x]);
	}
	if(ret>=1LL<<60) ret=-1;
	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