| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 975536 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 2273 ms | 262148 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int s, n;
vector<pair<int, int> > cake[2005];
int memo[20005][2005];
vector<pair<int, int> > v;
int sizee;
int dp(int idx, int we){
if(we < 0){
return INT_MIN;
}
if(idx < 0){
return 0;
}
int &res = memo[idx][we];
if(res != -1) return res;
auto [a,b] = v[idx];
return res = max(dp(idx - 1, we), dp(idx - 1, we - a) + b);
}
int main(){
memset(memo, -1, sizeof memo);
cin >> s >> n;
for(int i = 1; i<=n; i++){
int x, y, z;
cin >> x >> y >> z;
cake[y].push_back({x, z});
}
for(int i = 1; i<=2000; i++){
sort(cake[i].rbegin(), cake[i].rend());
int used = 2000;
int j = 0;
while(used != 0 && j < cake[i].size()){
auto &[a, b] = cake[i][j];
v.push_back({i, a});
used--;
b--;
if(b == 0) j++;
}
}
sizee = v.size();
cout << dp(sizee - 1, s);
}컴파일 시 표준 에러 (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... | ||||
