이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ull unsigned long long
#define ed '\n'
#define pb push_back
#define int long long
#define ii pair<int,int>
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define fi first
#define se second
using namespace __gnu_pbds;
using namespace std;
int dp[2005];
vector<int> g[2005];
void solve() {
int s, n;
cin >> s >> n;
while(n--) {
int v, w, cnt;
cin >> v >> w >> cnt;
int tmp = 1;
while(cnt) {
int cv = v * min(tmp, cnt);
int cw = w * min(tmp, cnt);
if (cw <= s) g[cw].pb(cv);
cnt -= min(tmp, cnt);
tmp <<= 1;
}
}
for(int i = 1; i <= s; ++i) {
sort(g[i].begin(), g[i].end(), greater<int>());
for(int k = 0; k < min(s / i, (int)g[i].size()); ++k) {
int v = g[i][k];
for(int j = s; j >= i; --j) dp[j] = max(dp[j], dp[j - i] + v);
}
}
cout << dp[s];
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
if (fopen("cf.inp", "r")) {
freopen("cf.inp", "r", stdin);
//freopen("cf.inp", "w", stdout);
}
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | freopen("cf.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |