제출 #887773

#제출 시각아이디문제언어결과실행 시간메모리
887773conthoancoKnapsack (NOI18_knapsack)C++14
73 / 100
1087 ms1628 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define II pair < int , int > #define pb push_back #define mset(a , b) memset(a , b , sizeof a) #define all(a) (a).begin() , (a).end() const int N = 1e5 + 5; int s, n, v[N], w[N], k[N], dp[2][N]; deque<II> dq; void input() { cin >> s >> n; for(int i = 1; i <= n; ++i) { cin >> v[i] >> w[i] >> k[i]; k[i] = min(k[i], s); } } void solve() { int res = 0; for(int i = 1; i <= n; ++i) { int id = i % 2; for(int r = 0; r < w[i]; ++r) { while(!dq.empty()) dq.pop_back(); for(int curS = r; curS <= s; curS += w[i]) { II curV = {dp[1 - id][curS] - (curS / w[i]) * v[i], curS}; while(!dq.empty() && dq.front().fi <= curV.fi) dq.pop_front(); while(!dq.empty() && dq.back().se < curS - k[i] * w[i]) dq.pop_back(); dq.push_front(curV); int preS = dq.back().se; // for(int preS = curS; preS >= 0; preS -= w[i]) dp[id][curS] = dp[1 - id][preS] + v[i] * (curS - preS) / w[i]; res = max(res, dp[id][curS]); } } } cout << res; } int main() { if(fopen("trash.inp" , "r")) freopen("trash.inp" , "r" , stdin) , freopen("trash.out" , "w" , stdout); // else freopen(".inp" , "r" , stdin) , freopen(".out" , "w" , stdout); ios::sync_with_stdio(0); cin.tie(0); input(); solve(); }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen("trash.inp" , "r" , stdin) , freopen("trash.out" , "w" , stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:45:53: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen("trash.inp" , "r" , stdin) , freopen("trash.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...