Submission #5942211
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<LL>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VS = vector<string>;
using PII = pair<LL, LL>;
using VP = vector<PII>;
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x, c) for (auto x : (c))
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) stable_sort(ALL(c))
#define RSORT(c) stable_sort((c).rbegin(), (c).rend())
#define FSORT(c) stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c) stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c) stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c) stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}
LL knapsackZeroOne(LL N, LL W, VI& weight, VI& value) { // weight & value must be 1-indexed
VVI dp(N + 1, VI(W + 1)); // dp[i][j] = max value sum with weight <= j using up to i-th objects
FOR(i, 1, N + 1) {
REP(j, W + 1) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]); // don't use object i
if (j - weight[i] >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - weight[i]] + value[i]); // use object i
}
}
return dp[N][W];
}
LL knapsackUnbounded(LL N, LL W, VI& weight, VI& value) { // weight & value must be 1-indexed
VVI dp(N + 1, VI(W + 1)); // dp[i][j] = max value sum with weight <= j using up to i-th objects
FOR(i, 1, N + 1) {
REP(j, W + 1) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]); // don't use object i
if (j - weight[i] >= 0) dp[i][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]); // use object i
}
}
return dp[N][W];
}
int main() {
LL N;
cin >> N;
VVI R(2, VI(3 + 1));
REP(i, 2) {
FOR(j, 1, 3 + 1) {
cin >> R[i][j];
}
}
VI weight(3 + 1), value(3 + 1);
FOR(i, 1, 3 + 1) {
weight[i] = R[0][i];
value[i] = R[1][i] - R[0][i]; // consider the difference (how many N increases)
}
N += knapsackUnbounded(3, N, weight, value); // A -> B
FOR(i, 1, 3 + 1) {
weight[i] = R[1][i];
value[i] = R[0][i] - R[1][i]; // consider the difference (how many N increases)
}
N += knapsackUnbounded(3, N, weight, value); // B -> A
cout << N << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Squirrel Merchant |
| User | yetnone |
| Language | C++14 (GCC 5.4.1) |
| Score | 600 |
| Code Size | 2724 Byte |
| Status | AC |
| Exec Time | 524 ms |
| Memory | 976996 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt |
| All | 00.txt, 41.txt, 42.txt, 45.txt, 50.txt, 55.txt, 60.txt, 65.txt, 70.txt, 75.txt, 80.txt, 81.txt, 82.txt, 83.txt, 84.txt, 85.txt, 86.txt, 87.txt, 88.txt, 89.txt, 90.txt, 91.txt, 92.txt, 93.txt, 94.txt, 95.txt, a01.txt, a02.txt, a03.txt, a04.txt, a05.txt, a06.txt, a07.txt, a08.txt, a09.txt, a10.txt, a11.txt, a12.txt, a13.txt, a14.txt, a15.txt, a16.txt, a17.txt, a18.txt, a19.txt, a20.txt, a21.txt, a22.txt, a23.txt, a24.txt, a25.txt, a26.txt, a27.txt, a28.txt, a29.txt, a30.txt, a31.txt, a32.txt, a33.txt, a34.txt, a35.txt, a36.txt, a37.txt, a38.txt, a39.txt, a40.txt, s1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00.txt | AC | 1 ms | 256 KiB |
| 41.txt | AC | 1 ms | 256 KiB |
| 42.txt | AC | 1 ms | 256 KiB |
| 45.txt | AC | 1 ms | 256 KiB |
| 50.txt | AC | 1 ms | 256 KiB |
| 55.txt | AC | 4 ms | 4476 KiB |
| 60.txt | AC | 3 ms | 3712 KiB |
| 65.txt | AC | 1 ms | 768 KiB |
| 70.txt | AC | 1 ms | 256 KiB |
| 75.txt | AC | 1 ms | 764 KiB |
| 80.txt | AC | 1 ms | 384 KiB |
| 81.txt | AC | 1 ms | 488 KiB |
| 82.txt | AC | 95 ms | 193136 KiB |
| 83.txt | AC | 86 ms | 173928 KiB |
| 84.txt | AC | 99 ms | 199932 KiB |
| 85.txt | AC | 96 ms | 195952 KiB |
| 86.txt | AC | 377 ms | 787072 KiB |
| 87.txt | AC | 169 ms | 344444 KiB |
| 88.txt | AC | 327 ms | 679424 KiB |
| 89.txt | AC | 53 ms | 106220 KiB |
| 90.txt | AC | 40 ms | 74880 KiB |
| 91.txt | AC | 1 ms | 484 KiB |
| 92.txt | AC | 1 ms | 484 KiB |
| 93.txt | AC | 1 ms | 484 KiB |
| 94.txt | AC | 524 ms | 976996 KiB |
| 95.txt | AC | 364 ms | 756972 KiB |
| a01.txt | AC | 507 ms | 964452 KiB |
| a02.txt | AC | 463 ms | 961380 KiB |
| a03.txt | AC | 459 ms | 954084 KiB |
| a04.txt | AC | 457 ms | 956136 KiB |
| a05.txt | AC | 465 ms | 961764 KiB |
| a06.txt | AC | 453 ms | 950376 KiB |
| a07.txt | AC | 465 ms | 967012 KiB |
| a08.txt | AC | 459 ms | 959076 KiB |
| a09.txt | AC | 452 ms | 944488 KiB |
| a10.txt | AC | 461 ms | 965220 KiB |
| a11.txt | AC | 460 ms | 964708 KiB |
| a12.txt | AC | 453 ms | 949604 KiB |
| a13.txt | AC | 1 ms | 484 KiB |
| a14.txt | AC | 1 ms | 484 KiB |
| a15.txt | AC | 1 ms | 484 KiB |
| a16.txt | AC | 2 ms | 996 KiB |
| a17.txt | AC | 1 ms | 484 KiB |
| a18.txt | AC | 1 ms | 484 KiB |
| a19.txt | AC | 1 ms | 612 KiB |
| a20.txt | AC | 1 ms | 484 KiB |
| a21.txt | AC | 1 ms | 484 KiB |
| a22.txt | AC | 1 ms | 484 KiB |
| a23.txt | AC | 2 ms | 996 KiB |
| a24.txt | AC | 2 ms | 740 KiB |
| a25.txt | AC | 1 ms | 484 KiB |
| a26.txt | AC | 1 ms | 484 KiB |
| a27.txt | AC | 1 ms | 484 KiB |
| a28.txt | AC | 1 ms | 612 KiB |
| a29.txt | AC | 2 ms | 996 KiB |
| a30.txt | AC | 1 ms | 484 KiB |
| a31.txt | AC | 1 ms | 484 KiB |
| a32.txt | AC | 1 ms | 484 KiB |
| a33.txt | AC | 1 ms | 484 KiB |
| a34.txt | AC | 3 ms | 3300 KiB |
| a35.txt | AC | 2 ms | 740 KiB |
| a36.txt | AC | 2 ms | 868 KiB |
| a37.txt | AC | 1 ms | 484 KiB |
| a38.txt | AC | 1 ms | 484 KiB |
| a39.txt | AC | 1 ms | 484 KiB |
| a40.txt | AC | 1 ms | 484 KiB |
| s1.txt | AC | 1 ms | 256 KiB |