이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define int long long
#define ff first
#define ss second
#define tobit(n) bitset<20>(n) //выводит 20 элементов в битовую систему
#define all(v) (v).begin(), (v).end()
#define rtt(v, k) rotate(v.begin(), v.begin() + k, v.end()); //move k elements back
const int MOD = 1e9 + 7;
int binpownm(int n, int m){
if(m == 1) return n;
if(m % 2 == 0){
int t = binpownm(n, m / 2); return t * t;
} else return binpownm(n, m - 1) * n;
}
bool sortt(pair<int, double> a, pair<int, double> b){
return a.ss < b.ss;
}
struct sturc_t {
int ff_, ss_, tt_;
};
int knaps(vector<int>& cur, vector<int>& cst, int S){
vector<vector<int>> dp(S + 1, vector<int> (cur.size() + 1, 0));
for(int j = 1; j <= cur.size(); j++){
for(int w = 1; w <= S; w++){
if(cur[j-1] <= w){
dp[w][j] = max(dp[w][j - 1], dp[w - cur[j - 1]][j - 1] + cst[j - 1]);
} else dp[w][j] = dp[w][j - 1];
}
} return dp[S][cur.size()];
}
int knapsack2(vector<sturc_t>& v, int S){
vector<int> dp(S + 1, 0);
for(auto& to : v){
for(int q = 0; q < to.tt_; q++){
for(int w = S; w >= to.ss_; w--){
dp[w] = max(dp[w], dp[w - to.ss_] + to.ff_);
}
}
} return dp[S];
}
const int N = 1e5+5, M = 2e3+5;
vector<pair<int, int>> res(N * 30);
int dp[M];
signed main(){
int S, N, cnt = 0; cin >> S >> N;
for(int i = 1; i <= N; i++){
int v, w, k; cin >> v >> w >> k;
for(int j = 1; j <= k; j <<= 1){
res[++cnt] = make_pair(v * j, w * j); k -= j;
} if(k > 0) res[++cnt] = make_pair(v*k,w*k);
} for(int i = 1; i <= cnt; i++){
for(int j = S; j >= res[i].ss; j--){
dp[j] = max(dp[j], dp[j-res[i].ss] + res[i].ff);
}
} cout << dp[S] << '\n';
}
// NEED TO FAST CIN && COUT //
const int fastIO = [](){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
return 0;
}();
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'long long int knaps(std::vector<long long int>&, std::vector<long long int>&, long long int)':
knapsack.cpp:25:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int j = 1; j <= cur.size(); j++){
| ~~^~~~~~~~~~~~~
# | 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... |