結果

問題 No.288 貯金箱の仕事
ユーザー 👑 kmjpkmjp
提出日時 2015-10-09 23:04:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 146,604 KB
実行使用メモリ 5,564 KB
最終ジャッジ日時 2023-09-27 10:18:13
合計ジャッジ時間 9,247 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,292 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 3 ms
5,292 KB
testcase_03 AC 3 ms
5,392 KB
testcase_04 AC 3 ms
5,256 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 59 ms
5,316 KB
testcase_08 AC 3 ms
5,520 KB
testcase_09 AC 47 ms
5,216 KB
testcase_10 AC 4 ms
5,212 KB
testcase_11 AC 25 ms
5,252 KB
testcase_12 AC 4 ms
5,340 KB
testcase_13 AC 38 ms
5,280 KB
testcase_14 AC 4 ms
5,340 KB
testcase_15 AC 55 ms
5,380 KB
testcase_16 AC 51 ms
5,256 KB
testcase_17 AC 3 ms
5,356 KB
testcase_18 AC 31 ms
5,348 KB
testcase_19 AC 3 ms
5,240 KB
testcase_20 AC 3 ms
5,308 KB
testcase_21 AC 29 ms
5,248 KB
testcase_22 AC 47 ms
5,320 KB
testcase_23 AC 372 ms
5,316 KB
testcase_24 AC 189 ms
5,288 KB
testcase_25 AC 5 ms
5,204 KB
testcase_26 AC 5 ms
5,344 KB
testcase_27 AC 5 ms
5,376 KB
testcase_28 AC 5 ms
5,332 KB
testcase_29 AC 5 ms
5,380 KB
testcase_30 AC 118 ms
5,212 KB
testcase_31 AC 118 ms
5,316 KB
testcase_32 AC 204 ms
5,260 KB
testcase_33 AC 204 ms
5,388 KB
testcase_34 AC 288 ms
5,480 KB
testcase_35 AC 289 ms
5,440 KB
testcase_36 AC 372 ms
5,344 KB
testcase_37 AC 111 ms
5,260 KB
testcase_38 AC 262 ms
5,344 KB
testcase_39 AC 129 ms
5,564 KB
testcase_40 AC 134 ms
5,312 KB
testcase_41 AC 356 ms
5,340 KB
testcase_42 AC 310 ms
5,276 KB
testcase_43 AC 47 ms
5,208 KB
testcase_44 AC 167 ms
5,248 KB
testcase_45 AC 294 ms
5,252 KB
testcase_46 AC 315 ms
5,296 KB
testcase_47 AC 216 ms
5,396 KB
testcase_48 AC 233 ms
5,344 KB
testcase_49 AC 91 ms
5,312 KB
testcase_50 AC 191 ms
5,312 KB
testcase_51 AC 142 ms
5,408 KB
testcase_52 AC 195 ms
5,208 KB
testcase_53 AC 249 ms
5,316 KB
testcase_54 AC 178 ms
5,352 KB
testcase_55 AC 3 ms
5,240 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],ne[501];
ll K[501];
ll can[400000];
ll tot;

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