Submission #1101833

#TimeUsernameProblemLanguageResultExecution timeMemory
1101833akamizaneKnapsack (NOI18_knapsack)C++17
0 / 100
1 ms336 KiB
#include<bits/stdc++.h> using namespace std; #define debug(...) 40 using ll = long long; using pii = pair<long long,int>; #define el cout << '\n' #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FOD(i, a, b) for (int i = (a); i >= (b); i--) #define REP(i, n) for (int i = 0; i < (n); i++) template <class T1, class T2>bool chmax(T1 &a, T2 b){return a < b ? a = b, 1 : 0;} template <class T1, class T2>bool chmin(T1 &a, T2 b){return a > b ? a = b, 1 : 0;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mod = 1e9 + 7; const int maxn = 1e5 + 5; void solve(){ ll s; int n; cin >> s >> n; map<int, vector<pii>> mp; REP(i, n){ int v, w, k; cin >> v >> w >> k; mp[w].pb({v, k}); } int m = mp.size(); vector<vector<ll>> dp(m + 1, vector<ll> (s + 1)); int cur = 0; for (auto [w, v] : mp){ vector<pii> a = v; sort(a.begin(), a.end(), [](pii x, pii y){ return x.fi > y.fi; }); debug(a); for (int i = 0; i <= s; i++){ chmax(dp[cur + 1][i], dp[cur][i]); } int idx1 = 0; int idx2 = 0; int cnt = 1; ll weight; ll val = 0; while(true){ weight = cnt * w; val += a[idx2].fi; debug(cur, weight, val); idx1++; if (weight > s) break; for (int i = 0; i + weight <= s; i++){ chmax(dp[cur + 1][i + weight], dp[cur][i] + val); } if (idx1 == a[idx2].se){ idx2++; if (idx2 == a.size()){ break; } idx1 = 0; } cnt++; } cur++; } debug(mp); debug(dp); cout << *max_element(all(dp[m - 1])); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tests = 1; // cin >> tests; for (int _ = 1; _ <= tests; _++){ cerr << "- Case #" << _ << ": \n"; solve(); el; } return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:4:20: warning: statement has no effect [-Wunused-value]
    4 | #define debug(...) 40
      |                    ^~
knapsack.cpp:44:3: note: in expansion of macro 'debug'
   44 |   debug(a);
      |   ^~~~~
knapsack.cpp:4:20: warning: statement has no effect [-Wunused-value]
    4 | #define debug(...) 40
      |                    ^~
knapsack.cpp:56:5: note: in expansion of macro 'debug'
   56 |     debug(cur, weight, val);
      |     ^~~~~
knapsack.cpp:64:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |       if (idx2 == a.size()){
      |           ~~~~~^~~~~~~~~~~
knapsack.cpp:4:20: warning: statement has no effect [-Wunused-value]
    4 | #define debug(...) 40
      |                    ^~
knapsack.cpp:73:2: note: in expansion of macro 'debug'
   73 |  debug(mp);
      |  ^~~~~
knapsack.cpp:4:20: warning: statement has no effect [-Wunused-value]
    4 | #define debug(...) 40
      |                    ^~
knapsack.cpp:74:2: note: in expansion of macro 'debug'
   74 |  debug(dp);
      |  ^~~~~
#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...