結果
| 問題 |
No.2364 Knapsack Problem
|
| コンテスト | |
| ユーザー |
detteiuu
|
| 提出日時 | 2025-03-04 03:50:41 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 614 ms / 3,000 ms |
| コード長 | 1,391 bytes |
| コンパイル時間 | 1,480 ms |
| コンパイル使用メモリ | 104,732 KB |
| 実行使用メモリ | 8,608 KB |
| 最終ジャッジ日時 | 2025-03-04 03:50:48 |
| 合計ジャッジ時間 | 7,186 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
int N, M, W;
cin >> N >> M >> W;
vector<int> A(N), B(N), C(M), D(M);
for (int i = 0; i < N; ++i) cin >> A[i];
for (int i = 0; i < N; ++i) cin >> B[i];
for (int i = 0; i < M; ++i) cin >> C[i];
for (int i = 0; i < M; ++i) cin >> D[i];
int ans = 0;
vector<int> perm1(N);
iota(perm1.begin(), perm1.end(), 0);
vector<int> perm2(M);
iota(perm2.begin(), perm2.end(), 0);
do {
do {
int idx1 = 0, idx2 = 0;
int w = 0, v = 0;
while (idx1 < N) {
if (w + A[perm1[idx1]] <= W) {
w += A[perm1[idx1]];
v += B[perm1[idx1]];
ans = max(ans, v);
++idx1;
} else {
while (idx2 < M && W < w + A[perm1[idx1]]) {
w -= C[perm2[idx2]];
v -= D[perm2[idx2]];
++idx2;
}
if (W < w + A[perm1[idx1]] || w < 0) {
break;
}
}
}
} while (next_permutation(perm2.begin(), perm2.end()));
} while (next_permutation(perm1.begin(), perm1.end()));
cout << ans << endl;
return 0;
}
detteiuu