제출 #1070434

#제출 시각아이디문제언어결과실행 시간메모리
1070434seoul_koreaKnapsack (NOI18_knapsack)C++17
73 / 100
1097 ms18636 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const bool multiTest = 0; #define TASK "" mt19937 rng(time(0)); const int maxN = 2222; struct Pack { ll w, v; }; ll totalW; int n; vector<Pack> packs; ll dp[maxN]; void solve(int curTest) { //cerr << "\n>TEST #" << curTest << "<\n"; // GET AC PLEASE cin >> totalW >> n; for(int i = 1; i <= n; i++) { ll v, w, k; cin >> v >> w >> k; int phanTach = 1; while(k - phanTach >= 0) { packs.push_back({w * phanTach, v * phanTach}); k -= phanTach; phanTach *= 2; } if(k > 0) packs.push_back({w * k, v * k}); } memset(dp, -0x3f, sizeof dp); dp[0] = 0; for(auto pack : packs) { for(ll s = totalW; s >= pack.w; s--) { dp[s] = max(dp[s], dp[s - pack.w] + pack.v); } } cout << *max_element(dp, dp + totalW + 1) << endl; } main() { cin.tie(0)->ios_base::sync_with_stdio(0); if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin); if(fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } int nTest = 1; if(multiTest) cin >> nTest; for(int iTest = 1; iTest <= nTest; iTest++) solve(iTest); return 0; }

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

knapsack.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main() {
      | ^~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:49:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         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...