| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 648121 | Lextyle | Knapsack (NOI18_knapsack) | C++17 | 167 ms | 236708 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma warning(disable : 6031)
#define USACO freopen("feast.in", "r", stdin); freopen("feast.out", "w+", stdout);
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;
/*
*/
ll dp[15519][2001];
pair<int, pair<int, int>> a[100000];
pair<int, int> b[15518];
bool pred(pair<int, pair<int, int>> a1, pair<int, pair<int, int>> a2) {
if (a1.first < a2.first) return 1;
else if (a1.first == a2.first) return a1.second.first > a2.second.first;
return 0;
}
int main() {
//USACO;
fastIO;
int s, n;
cin >> s >> n;
for (int i = 0; i < n; i++) cin >> a[i].second.first >> a[i].first >> a[i].second.second;
sort(a, a + n, pred);
int cnt = 0, ind = 0;
for (int i = 0; i < n; i++) {
if (i == 0 || a[i].first != a[i - 1].first) cnt = 0;
for (int j = 0; cnt < s / a[i].first && j < a[i].second.second; j++) {
b[ind++] = { a[i].first, a[i].second.first };
cnt++;
}
}
for (int i = 1; i <= ind; i++) {
for (int j = b[i - 1].first; j <= s; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i - 1].first] + b[i - 1].second);
}
}
cout << dp[ind][s] << "\n";
}컴파일 시 표준 에러 (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... | ||||
