結果

問題 No.2364 Knapsack Problem
ユーザー airthsairths
提出日時 2023-06-30 21:35:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,102 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 132,388 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-21 15:26:43
合計ジャッジ時間 2,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 4 ms
4,384 KB
testcase_11 AC 2 ms
4,504 KB
testcase_12 WA -
testcase_13 AC 10 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * 
 * 	^v^
 * 
 */
#include <iostream>
#include <numeric>
#include <set>
#include <iomanip>
#include <chrono>
#include <queue>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <algorithm>
#include <array>
#include <random>

using namespace std;

using ll = long long int;
using ld = long double;

#define iamtefu ios_base::sync_with_stdio(false); cin.tie(0);
#define fl(i,a,n) for (ll i(a); i<n; i++)
#define rfl(i,a,n) for (ll i(n-1); i>=a; i--)
#define ty int _; for(cin>>_; _--;)
#define print(a) for(auto ele:a){cout<<ele<<" ";}cout<<'\n';

ll gcd(ll a, ll b){
	if (b==0){
		return a;
	}
	return gcd(b, a%b);
}

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

ll pw(ll a, ll b, ll m){
	ll res=1;
	a%=m;
	while (b){
		if (b&1){
			res=(res*a)%m;
		}
		a=(a*a)%m;
		b/=2;
	}
	return res;
}

void scn(){
	ll n, m, w; cin>>n>>m>>w;
	vector <ll> a(n), b(n), c(m), d(m);
	fl(i,0,n){
		cin>>a[i];
	}
	fl(i,0,n){
		cin>>b[i];
	}
	fl(i,0,m){
		cin>>c[i];
	}
	fl(i,0,m){
		cin>>d[i];
	}
	ll ans = 0;
	fl(i,0,(1<<(n+m))){
		ll wi = 0, vi = 0, don = 0;
		multiset <ll> st;
		fl(j,0,n+m){
			if ((i&(1<<j))){
				if (j>=n){
					// wi-=c[j-n];
					st.insert(-c[j-n]);
					vi-=d[j-n];
				} else {
					// wi+=c[j];
					st.insert(a[j]);
					// if (wi>w){
					// 	don++;
					// }
					vi+=b[j];
				}
			}
		}
		while (st.size()){
			ll upd = 0;
			for (auto x:st){
				if (x+wi>=0 && x+wi<=w){
					upd++;
					wi+=x;
					st.erase(st.find(x));
					break;
				}
			}
			if (upd==0){
				break;
			}
		}
		if (don==0 && st.size()==0){
			ans = max(ans, vi);
		}
	}
	cout<<ans<<'\n';

	// not necessarily distinct
	// right down
}

int main(){
	iamtefu;
#if defined(airths)
	auto t1=chrono::high_resolution_clock::now();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// ty
	{
		scn();
	}
#if defined(airths)
	auto t2=chrono::high_resolution_clock::now();
	ld ti=chrono::duration_cast<chrono::nanoseconds>(t2-t1).count();
	ti*=1e-6;
	cerr<<"Time: "<<setprecision(12)<<ti;
	cerr<<"ms\n";
#endif
	return 0;
}
0