結果

問題 No.2364 Knapsack Problem
ユーザー tailstails
提出日時 2023-07-03 11:42:58
言語 cLay
(20240104-1)
結果
AC  
実行時間 3 ms / 3,000 ms
コード長 458 bytes
コンパイル時間 3,145 ms
コンパイル使用メモリ 165,460 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 08:45:21
合計ジャッジ時間 4,422 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

ll@n,@m,@w,@a[n],@b[],@c[m],@d[],z=0;
vector<array<ll,3>>v;
char u[1<<14]{};
v.push_back({0,0,0});
while(!v.empty()){
	auto x=v.back();
	v.pop_back();
	if(z<x[2]){
		z=x[2];
	}
	rep(i,n){
		if(!(x[0]&1<<i)&&x[1]+a[i]<=w){
			ll j=x[0]|1<<i;
			if(!u[j]++){
				v.push_back({j,x[1]+a[i],x[2]+b[i]});
			}
		}
	}
	rep(i,m){
		if(!(x[0]&1<<n+i)&&x[1]-c[i]>=0){
			ll j=x[0]|1<<n+i;
			if(!u[j]++){
				v.push_back({j,x[1]-c[i],x[2]-d[i]});
			}
		}
	}
}
wt(z);
0