제출 #1033291

#제출 시각아이디문제언어결과실행 시간메모리
1033291vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
1098 ms48216 KiB
#include <bits/stdc++.h> using namespace std; #define int long long void solve() { int s, n; cin >> s >> n; vector<int> dp(s + 1, 0); for (int i = 0; i < n; ++i) { int v, w, k; cin >> v >> w >> k; for (int b = 1; k > 0; b *= 2) { int num = min(b, k); k -= num; int tv = num * v; int tw = num * w; for (int j = s; j >= tw; --j) { dp[j] = max(dp[j], dp[j - tw] + tv); } } } cout << *max_element(dp.begin(), dp.end()) << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // Directly use C-style I/O for even faster performance #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif solve(); return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen("output.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...