# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
482688 | Olympia | Knapsack (NOI18_knapsack) | C++17 | 12 ms | 3520 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cmath>
#include <iostream>
#include <set>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <iomanip>
#include <type_traits>
#include <string>
#include <queue>
#include <map>
using namespace std;
#define ll long long
struct item {
long long weight;
long long worth;
long long cnt;
};
bool comp (item i1, item i2) {
if (i1.weight == i2.weight) {
return (i1.worth > i2.worth);
}
return (i1.weight < i2.weight);
}
int main() {
freopen("hamming.in", "r", stdin);
long long S, N;
cin >> S >> N;
vector<item> items;
for (int i = 0; i < N; i++) {
long long wei, wor;
cin >> wor >> wei;
long long cnt;
cin >> cnt;
items.push_back({wei, wor, cnt});
}
sort(items.begin(), items.end(), comp);
long long dp[S + 1];
for (int j = 0; j <= S; j++) {
dp[j] = 0;
}
long long myMax = 0;
long long prev_weight = -1;
long long soFar = 0;
for (int i = 1; i <= items.size(); i++) {
if (items[i - 1].weight == prev_weight) {
soFar++;
} else {
soFar = 0;
prev_weight = items[i - 1].weight;
}
if (soFar * items[i - 1].weight > S) {
continue;
}
soFar += items[i - 1].cnt;
for (int j = S; j >= 0; j--) {
int cntr = 0;
while (cntr * items[i - 1].weight <= j && cntr <= items[i - 1].cnt) {
dp[j] = max(dp[j], dp[j - cntr * items[i - 1].weight] + cntr * items[i - 1].worth);
cntr++;
//soFar++;
}
myMax = max(myMax, dp[j]);
}
}
cout << myMax << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |