이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#define all(x) x.begin(), x.end()
#define ON(a, b) (a >> b & 1)
template<typename T> bool maximise(T &a, T b){if(a < b){a = b; return 1;} return 0;}
template<typename T> bool minimise(T &a, T b){if(a > b){a = b; return 1;} return 0;}
const int N = 2001;
int s, n;
vector<pair<ll, int>> weight[N];
ll dp[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> s >> n;
for(int i = 1, v, w, k; i <= n; ++i){
cin >> v >> w >> k;
weight[w].push_back({v, k});
}
for(int i = 1; i <= s; ++i) sort(all(weight[i]), greater<pair<ll, int>>());
for(int i = 1; i <= s; ++i){
for(int j = 1; j <= s; ++j){
int cur = 0, id = 0, cnt = 0; ll val = 0;
maximise(dp[i][j], dp[i - 1][j]);
for(int t = i; t <= j; t += i){
while(id < (int)weight[i].size() && cur < t){
if(cnt >= weight[i][id].second){
cnt = 0;
id++;
}
cnt++; cur += i; val += weight[i][id].first;
}
if(id >= weight[i].size()) break;
maximise(dp[i][j], dp[i - 1][j - t] + val);
}
}
}
ll ans = 0;
for(int i = 1; i <= s; ++i) maximise(ans, dp[s][i]);
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if(id >= weight[i].size()) break;
| ~~~^~~~~~~~~~~~~~~~~~~
# | 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... |