제출 #952354

#제출 시각아이디문제언어결과실행 시간메모리
952354wiiKnapsack (NOI18_knapsack)C++17
100 / 100
35 ms6104 KiB
#include <bits/stdc++.h> using namespace std; typedef double db; typedef long long ll; typedef long double ld; #define int ll typedef pair<int, int> pii; #define lx (id << 1) #define rx (lx | 1) #define gcd __gcd #define pb push_back #define all(x) (x).begin(), (x).end() #define bit(i, mask) ((mask) >> (i) & 1) #define reset(x, val) memset(x, val, sizeof(x)) #define foru(i,a,b) for(int i = (a); i <= (b); ++i) #define ford(i,a,b) for(int i = (a); i >= (b); --i) #define FastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); template<typename T> bool maximize(T &res, const T &val) { if (res < val) { res = val; return true; } return false; } template<typename T> bool minimize(T &res, const T &val) { if (val < res) { res = val; return true; } return false; } const ll Linf = 0x3f3f3f3f3f3f3f3f; const int Inf = 0x3f3f3f3f; const ll Mod = 1e9 + 7; const ll Mod2 = ll(1e9) + 9; const int Lim = 1e6 + 5; const int inv6 = 166666668; /// ====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*==== const int base = 3; const int N = 1e5 + 5; const int K = 2e3 + 5; const int dx[] = {+1, -1, 0, 0}; const int dy[] = {0, 0, +1, -1}; const int block_size = sqrt(2e9) + 2; struct good { int value, cost, count; good(int v, int c, int k): value(v), cost(c), count(k) {} friend bool operator< (const good &a, const good &b) { return a.value == b.value ? a.cost < b.cost : a.value > b.value; } }; int n, s; int dp[K]; void solve() { cin >> s >> n; vector<good> a; foru(i, 1, n) { int v, c, k; cin >> v >> c >> k; a.emplace_back(v, c, k); } int last = Inf; sort(all(a)); for (auto &x: a) { if (x.cost >= last) continue; foru(_, 1, x.count) { int ok = 0; ford(w, s, x.cost) { ok |= maximize(dp[w], dp[w - x.cost] + x.value); } if (!ok) { last = x.cost; break; } } } cout << dp[s]; } signed main() { FastIO; #define task "" if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } #define task "test" if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int ntest = 1; // cin >> ntest; while (ntest--) { //cout << "Case " << q << ": " << "\n"; solve(); cout << "\n"; } return 0; } /** /\_/\ * (= ._.) * / >TL \>AC **/

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

knapsack.cpp:95: warning: "task" redefined
   95 |     #define task "test"
      | 
knapsack.cpp:89: note: this is the location of the previous definition
   89 |     #define task ""
      | 
knapsack.cpp: In function 'int main()':
knapsack.cpp:91:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:92:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:97:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:98:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |   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...