제출 #1060879

#제출 시각아이디문제언어결과실행 시간메모리
1060879trandangquangKnapsack (NOI18_knapsack)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define task "p1" #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define sz(a) (int)(a).size() #define all(a) (a).begin(), (a).end() #define bit(s, i) (((s) >> (i)) & 1) #define ii pair <int, int> #define vii vector <ii> #define vi vector <int> #define fi first #define se second #define ll long long #define eb emplace_back #define pb push_back #define __builtin_popcount __builtin_popcountll void solve(); int32_t main() { if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin.tie(0)->sync_with_stdio(0); int tc = 1; // cin >> tc; FOR(i, 1, tc) { solve(); } } const int N = 1e5+5; int n, m, dp[N]; vii item; void solve() { cin >> m >> n; FOR(i, 1, n) { int w, v, num; cin >> w >> v >> num; FOR(b, 0, 10) { int t = (1<<b); if(num >= t) { num -= t; int nww = t*w, nwv = t*v; item.eb(nww, nwv); } } int rest = min(num, m/w); item.eb(rest*w, rest*v); } FOR(i, 0, sz(item)-1) { int w = item[i].fi, v = item[i].se; FORD(j, m, w) { dp[j] = max(dp[j], dp[j-w] + v); } } cout << dp[m]; }

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

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   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...