제출 #1321948

#제출 시각아이디문제언어결과실행 시간메모리
1321948jim_xKnapsack (NOI18_knapsack)C++17
73 / 100
1095 ms608 KiB
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <set> #include <cmath> #include <numeric> #include <queue> #include <stack> #include <iomanip> using namespace std; void baseIO(string s = ""){ ios_base::sync_with_stdio(0); cin.tie(0); if (s.size()){ freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } } int main() { baseIO(); int s, n; cin >> s >> n; vector<multiset<int>> by_weight(s + 1); for (int i = 0; i < n; i++){ int a, b, c; cin >> a >> b >> c; c = min(c, s / b); while (c--){ by_weight[b].insert(a); if (by_weight[b].size() > s / b) by_weight[b].erase(by_weight[b].begin()); } } int dp[s + 1]{}; for (int w = 1; w <= s; w++){ for (auto &val : by_weight[w]){ for (int pos = s; pos >= w; pos--) dp[pos] = max(dp[pos], dp[pos - w] + val); } } cout << *max_element(dp, dp + s + 1); return 0; }

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

knapsack.cpp: In function 'void baseIO(std::string)':
knapsack.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((s + ".out").c_str(), "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...