| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 475254 | nohaxjustsoflo | Knapsack (NOI18_knapsack) | C++17 | 85 ms | 3948 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
const int mxN = 2005;
const int mod = 1e9+7;
const int mxlogN = 20;
const int mxK = 10;
vector<pair<int, int>> a[mxN];
ll sum[mxN];
ll dp[mxN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int S, n; cin >> S >> n;
for(int i = 0; i < n; i++)
{
int V, W, K; cin >> V >> W >> K;
a[W].push_back({V, K});
}
vector<pair<int, int>> items; ///W V
for(int i = 1; i <= S; i++)
{
sort(a[i].begin(), a[i].end());
while(sum[i] < S && a[i].size())
{
while(sum[i] < S && a[i].back().second)
{
sum[i] += i;
a[i].back().second--;
items.push_back({i, a[i].back().first});
}
a[i].pop_back();
}
}
for(int i = 0; i < items.size(); i++)
{
for(int j = S; j >= items[i].first; j--)
{
if(items[i].second+dp[j-items[i].first] > dp[j])
{
dp[j] = items[i].second+dp[j-items[i].first];
}
}
}
cout << dp[S];
}
/**
1
8
1 0 1 1 0 1 1 1
*/
컴파일 시 표준 에러 (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... | ||||
