제출 #467706

#제출 시각아이디문제언어결과실행 시간메모리
467706ShinKnapsack (NOI18_knapsack)C++14
0 / 100
3 ms456 KiB
#include <bits/stdc++.h> #define fi first #define se second #define TASK "file" #define all(x) x.begin(), x.end() using namespace std; const int N = 2e3 + 7; const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const long long INFLL = 1e18 + 7; typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <class X, class Y> bool minimize(X &a, Y b) { if (a > b) return a = b, true; return false; } template <class X, class Y> bool maximize(X &a, Y b) { if (a < b) return a = b, true; return false; } struct Items { int v, k; Items(int _v = 0, int _k = 0) : v(_v), k(_k) {} bool operator <(const Items &a) const { return v > a.v; } }; int n, max_weight; ll dp[N]; vector<Items> w[N]; void solve(void) { cin >> max_weight >> n; for (int i = 1; i <= n; i ++) { int x, y, z; cin >> y >> x >> z; w[x].push_back(Items(y, z)); } for (int i = 1; i <= max_weight; i ++) { sort(all(w[i])); try { ll sum = 0; for (Items x: w[i]) while (x.k --) { for (int k = max_weight; k >= i; k --) maximize(dp[k], dp[k - i] + x.v); if (sum >= max_weight) throw 1; sum += i; } } catch(...) {} } cout << dp[max_weight]; } int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); #else #endif // ONLINE_JUDGE int test = 1; // cin >> test; while (test --) { solve(); } return 0; }

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

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