| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 794198 | Kalpit1810 | Knapsack (NOI18_knapsack) | C++17 | 121 ms | 34248 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n, s;
cin >> s >> n;
map<long long, vector<pair<long long, long long>>> items;
for (long long i = 0; i < n; i++)
{
long long a, b, c;
cin >> a >> b >> c;
items[b].push_back({a, c});
}
vector<vector<long long>> dp(items.size()+1, vector<long long>(s + 1, INT64_MIN));
dp[0][0]=0;
long long at = 1;
for (auto p : items)
{
long long w =p.first;
vector<pair<long long,long long>> item = p.second;
sort(item.begin(), item.end(), greater<pair<int, int>>());
for (int i = 0; i < s + 1; i++)
{
dp[at][i] = dp[at - 1][i];
long long copies = 0;
long long type = 0;
long long value = 0;
long long curr = 0;
while ((copies + 1) * w <= i && type < item.size())
{
value += item[type].first;
copies++;
curr++;
if(dp[at-1][i-copies*w] != INT64_MIN)
{
dp[at][i] = max(dp[at][i],dp[at-1][i-copies*w]+value);
}
if (curr==item[type].second){
curr=0;
type++;
}
}
}
at++;
}
cout << *max_element(dp.back().begin(), dp.back().end());
}컴파일 시 표준 에러 (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... | ||||
