제출 #984310

#제출 시각아이디문제언어결과실행 시간메모리
984310vjudge1Knapsack (NOI18_knapsack)C++14
100 / 100
103 ms28108 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mxn = 9 + 1e6; const int inf = 0x3f3f3f3f; const ll lnf = 0x3f3f3f3f3f3f3f3f; vector<int> obj[mxn]; void SaKaTa(void) { int s, n; cin >> s >> n; for (int i = 1; i <= n; ++i) { int v, w, k; cin >> v >> w >> k; k = min(k, s / w); int tmp = 1; while (k) { int V = v * tmp, W = w * tmp; obj[W].push_back(V); k -= tmp; tmp = min(tmp * 2, k); } } vector<int> dp(s + 1); for (int i = 1; i <= s; ++i) { sort(begin(obj[i]), end(obj[i]), greater<int>()); while ((int)obj[i].size() > (int) (s / i)) { obj[i].pop_back(); } for (int v : obj[i]) { for (int w = s; w >= i; --w) { dp[w] = max(dp[w], dp[w - i] + v); } } } cout << *max_element(begin(dp), end(dp)) << "\n"; } int32_t main(void) { #define task "SaKaTa" cin.tie(0)->sync_with_stdio(0); for (string iext : {"in", "inp"}) { if (fopen((task "." + iext).c_str(), "r")) { freopen((task "." + iext).c_str(), "r", stdin); freopen(task ".out", "w", stdout); } } int testcase = 1; // cin >> testcase; while (testcase--) SaKaTa(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:47:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |       freopen((task "." + iext).c_str(), "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:48:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |       freopen(task ".out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...