| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 648355 | thienbao1602 | Knapsack (NOI18_knapsack) | C++17 | 125 ms | 37152 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x.size())
#define pi pair<ll, ll>
#define fi first
#define se second
using namespace std;
const int N = 2e3 + 55;
const ll inf = -1e16;
int n, S;
ll best[N][N];
map<ll, vector<pi>> weight;
void solve()
{
cin >> S >> n;
for(int i=0; i<n; i++)
{
ll val, w, sl;
cin >> val >> w >> sl;
weight[w].push_back({val, sl});
}
memset(best, inf, sizeof(best));
best[0][0] = 0;
int id = 1;
for(auto [w, items] : weight)
{
sort(items.begin(), items.end(), greater<pi>());
for(int j=0; j<=S; j++)
{
best[id][j] = best[id - 1][j];
ll profit = 0, type_at = 0, sl = 0, used = 0;
while((sl + 1) * w <= j && type_at < sz(items))
{
sl++;
profit += items[type_at].fi;
if (best[id - 1][j - w * sl] != inf)
{
best[id][j] = max(best[id][j], best[id - 1][j - w * sl] + profit);
}
used++;
if (used == (ll)items[type_at].second)
{
used = 0;
type_at++;
}
}
}
id++;
}
ll ret = 0;
for(int j=0; j<=S; j++)
{
ret = max(ret, best[id - 1][j]);
}
cout << ret;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
컴파일 시 표준 에러 (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... | ||||
