제출 #886376

#제출 시각아이디문제언어결과실행 시간메모리
886376Zero_OPKnapsack (NOI18_knapsack)C++14
73 / 100
1032 ms18632 KiB
#include<bits/stdc++.h> using namespace std; #define range(v) begin(v), end(v) #define compact(v) v.erase(unique(range(v)), end(v)) template<class T> bool minimize(T& a, T b){ if(a > b) return a = b, true; return false; } template<class T> bool maximize(T& a, T b){ if(a < b) return a = b, true; return false; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; int S, n; void Zero_OP(){ cin >> S >> n; vector<pair<ll, int>> items; while(n--){ int v, w, k; cin >> v >> w >> k; k = min(k, S / w); int pw2 = 1; while(k >= pw2){ k -= pw2; if(1LL * w * pw2 <= 1LL * S){ items.push_back({1LL * v * pw2, w * pw2}); } pw2 <<= 1; } if(k > 0 and 1LL * w * k <= S){ items.push_back({1LL * v * k, w * k}); } } vector<ll> dp(S + 1, -1e18); dp[0] = 0; for(auto [earn, weight] : items){ for(int i = S; i >= weight; --i){ maximize(dp[i], dp[i - weight] + earn); } } cout << *max_element(range(dp)); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #define task "antuvu" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } Zero_OP(); return 0; }

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

knapsack.cpp: In function 'void Zero_OP()':
knapsack.cpp:49:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   49 |   for(auto [earn, weight] : items){
      |            ^
knapsack.cpp: In function 'int main()':
knapsack.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     freopen(task".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     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...