結果
| 問題 |
No.2364 Knapsack Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 21:35:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,102 bytes |
| コンパイル時間 | 1,238 ms |
| コンパイル使用メモリ | 129,224 KB |
| 最終ジャッジ日時 | 2025-02-15 03:34:55 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 WA * 10 |
ソースコード
/*
*
* ^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;
}