結果

問題 No.288 貯金箱の仕事
ユーザー chocoruskchocorusk
提出日時 2018-12-20 14:56:25
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,151 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 97,240 KB
実行使用メモリ 15,144 KB
最終ジャッジ日時 2023-10-26 01:00:10
合計ジャッジ時間 5,536 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
15,144 KB
testcase_01 AC 5 ms
8,136 KB
testcase_02 AC 5 ms
8,136 KB
testcase_03 AC 5 ms
8,136 KB
testcase_04 AC 5 ms
8,136 KB
testcase_05 AC 5 ms
8,136 KB
testcase_06 AC 5 ms
8,136 KB
testcase_07 AC 10 ms
8,136 KB
testcase_08 AC 5 ms
8,136 KB
testcase_09 AC 8 ms
8,136 KB
testcase_10 AC 6 ms
8,136 KB
testcase_11 AC 5 ms
8,136 KB
testcase_12 AC 5 ms
8,136 KB
testcase_13 AC 6 ms
8,136 KB
testcase_14 AC 6 ms
8,136 KB
testcase_15 AC 8 ms
8,136 KB
testcase_16 AC 7 ms
8,136 KB
testcase_17 AC 6 ms
8,136 KB
testcase_18 AC 5 ms
8,136 KB
testcase_19 AC 5 ms
8,136 KB
testcase_20 AC 5 ms
8,136 KB
testcase_21 AC 5 ms
8,136 KB
testcase_22 AC 7 ms
8,136 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
権限があれば一括ダウンロードができます

ソースコード

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>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF=1e18+1;
int main()
{
	int n; ll m;
	cin>>n>>m;
	ll a[500];
	ll sum=0;
	for(int i=0; i<n; i++){
		cin>>a[i];
		sum+=a[i];
	}
	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 sum1=sum;
	ll dp[2][300000];
	fill(dp[0], dp[0]+sum+1, INF);
	dp[0][0]=0;
	for(int t=0; t<60; t++){
		for(int i=0; i<n; i++){
			for(int j=sum1; j>=a[i]; j--){
				dp[t&1][j]=min(dp[t&1][j], dp[t&1][j-a[i]]+(1ll<<t));
			}
		}
		fill(dp[(t+1)&1], dp[(t+1)&1]+sum1/2+sum+1, INF);
		for(int j=(s&1); j<=sum1; j+=2){
			dp[(t+1)&1][j/2]=dp[t&1][j];
		}
		s>>=1;
		if(s==0){
			if(dp[(t+1)&1][0]<INF) cout<<dp[(t+1)&1][0]<<endl;
			else cout<<-1<<endl;
			return 0;
		}
		sum1=sum1/2+sum;
	}
	return 0;
}
0