結果

問題 No.288 貯金箱の仕事
ユーザー 👑 kmjpkmjp
提出日時 2015-10-09 22:57:42
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,191 bytes
コンパイル時間 1,232 ms
コンパイル使用メモリ 146,156 KB
実行使用メモリ 5,816 KB
最終ジャッジ日時 2023-09-27 10:14:43
合計ジャッジ時間 8,480 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,380 KB
testcase_09 RE -
testcase_10 AC 4 ms
4,380 KB
testcase_11 RE -
testcase_12 AC 4 ms
4,376 KB
testcase_13 RE -
testcase_14 AC 3 ms
4,376 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 2 ms
4,376 KB
testcase_18 RE -
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 9 ms
5,344 KB
testcase_26 AC 9 ms
5,292 KB
testcase_27 AC 9 ms
5,308 KB
testcase_28 AC 10 ms
5,476 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 AC 181 ms
4,380 KB
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 AC 355 ms
4,632 KB
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
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[300000];
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