結果

問題 No.288 貯金箱の仕事
ユーザー chocoruskchocorusk
提出日時 2018-12-11 22:05:02
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,175 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 96,992 KB
実行使用メモリ 23,180 KB
最終ジャッジ日時 2023-10-24 04:59:27
合計ジャッジ時間 27,104 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
23,172 KB
testcase_01 AC 21 ms
23,172 KB
testcase_02 AC 28 ms
23,172 KB
testcase_03 AC 18 ms
23,172 KB
testcase_04 AC 28 ms
23,172 KB
testcase_05 AC 15 ms
23,172 KB
testcase_06 AC 15 ms
23,172 KB
testcase_07 AC 148 ms
23,172 KB
testcase_08 AC 53 ms
23,172 KB
testcase_09 AC 113 ms
23,172 KB
testcase_10 AC 128 ms
23,172 KB
testcase_11 AC 67 ms
23,172 KB
testcase_12 AC 117 ms
23,172 KB
testcase_13 AC 98 ms
23,172 KB
testcase_14 AC 112 ms
23,172 KB
testcase_15 WA -
testcase_16 AC 122 ms
23,172 KB
testcase_17 AC 92 ms
23,172 KB
testcase_18 AC 73 ms
23,172 KB
testcase_19 AC 84 ms
23,172 KB
testcase_20 AC 58 ms
23,172 KB
testcase_21 AC 66 ms
23,172 KB
testcase_22 AC 112 ms
23,172 KB
testcase_23 AC 1,198 ms
23,172 KB
testcase_24 AC 618 ms
23,172 KB
testcase_25 AC 21 ms
23,172 KB
testcase_26 AC 21 ms
23,172 KB
testcase_27 AC 21 ms
23,172 KB
testcase_28 AC 21 ms
23,172 KB
testcase_29 AC 21 ms
23,172 KB
testcase_30 AC 319 ms
23,172 KB
testcase_31 AC 323 ms
23,172 KB
testcase_32 AC 623 ms
23,172 KB
testcase_33 AC 637 ms
23,172 KB
testcase_34 AC 948 ms
23,172 KB
testcase_35 AC 998 ms
23,172 KB
testcase_36 AC 1,460 ms
23,180 KB
testcase_37 AC 429 ms
23,172 KB
testcase_38 AC 1,017 ms
23,172 KB
testcase_39 AC 393 ms
23,172 KB
testcase_40 AC 403 ms
23,172 KB
testcase_41 AC 1,109 ms
23,172 KB
testcase_42 AC 978 ms
23,172 KB
testcase_43 AC 695 ms
23,172 KB
testcase_44 AC 499 ms
23,172 KB
testcase_45 AC 917 ms
23,172 KB
testcase_46 AC 1,014 ms
23,172 KB
testcase_47 AC 704 ms
23,172 KB
testcase_48 AC 723 ms
23,172 KB
testcase_49 AC 437 ms
23,172 KB
testcase_50 AC 571 ms
23,172 KB
testcase_51 AC 438 ms
23,172 KB
testcase_52 AC 625 ms
23,172 KB
testcase_53 AC 783 ms
23,172 KB
testcase_54 AC 543 ms
23,172 KB
testcase_55 AC 23 ms
23,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF=1e18+1;
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}
int main()
{
	int n; ll m;
	cin>>n>>m;
	ll a[500];
	for(int i=0; i<n; i++) cin>>a[i];
	ll g=a[0];
	for(int i=1; i<n; i++) g=gcd(a[i], g);
	for(int i=0; i<n; i++) a[i]/=g;
	if(m%g!=0){
	    cout<<-1<<endl;
	    return 0;
	}
	m/=g;
	ll s=0;
	for(int i=0; i<n; i++){
		ll k; cin>>k;
		s+=(a[i]*k);
	}
	if(s<m){
		cout<<-1<<endl;
		return 0;
	}
	s-=m;
	ll dp[2500001];
	fill(dp, dp+2500000, INF);
	dp[0]=0;
	for(int i=0; i<n-1; i++){
		for(int j=0; j<=2500000-a[i]; j++){
			dp[j+a[i]]=min(dp[j]+1, dp[j+a[i]]);
		}
	}
	ll ans=INF;
	for(ll i=s%a[n-1]; i<=min(2500000ll, s); i+=a[n-1]){
		if(dp[i]==INF) continue;
		ans=min(ans, dp[i]+(s-i)/a[n-1]);
	}
	if(ans<INF) cout<<ans<<endl;
	else cout<<-1<<endl;
	return 0;
}
0