제출 #1319314

#제출 시각아이디문제언어결과실행 시간메모리
1319314quan123Knapsack (NOI18_knapsack)C++20
73 / 100
1095 ms16160 KiB
#include <bits/stdc++.h> #define int long long using namespace std; template<typename T, typename... Args> void print(T t) {cout << t << '\n';} template<typename T, typename... Args> void print(T t, Args... args) {cout << t << " "; print(args...) ;} const int S = 2005 , MX = 1e9+7; int dp[S]; int n , s , cnt , ans = -MX; vector<int> v; vector<int> w; void file_input() { if (fopen("inp.txt" , "r")) { freopen("inp.txt" , "r" , stdin); freopen("out.txt" , "w" , stdout); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); file_input(); cin >> s >> n; while (n--) { int a , b , k , sm; cin >> a >> b >> k; sm = k; for (int p = 0; (k>>p) > 1; p++) { v.push_back(a<<p); w.push_back(b<<p); cnt++; sm -= (1<<p); } v.push_back(a*sm); w.push_back(b*sm); cnt++; } for (int i = 1; i < S; i++) {dp[i] = -1;} for (int i = 0; i < cnt; i++) { for (int p = s; p >= 0; p--) { if (dp[p] == -1) {continue;} if (p+w[i] > s) {continue;} dp[p+w[i]] = max(dp[p+w[i]] , dp[p]+v[i]); } } for (int p = 0; p <= s; p++) { ans = max(ans , dp[p]); } cout << ans; return 0; }

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

knapsack.cpp: In function 'void file_input()':
knapsack.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("inp.txt" , "r" , stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("out.txt" , "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...