Submission #1145343

#TimeUsernameProblemLanguageResultExecution timeMemory
1145343bluevioletKnapsack (NOI18_knapsack)C++20
73 / 100
1096 ms16800 KiB
#include <bits/stdc++.h> #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define io(x) if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);} #define mem(c, x) memset(c, x, sizeof(c)) #define all(c) c.begin(), c.end() #define bit(i,j) ((i >> j) & 1) #define pb push_back #define se second #define fi first #define el '\n' using namespace std; template<class T> bool maximize(T &a, const T &b) { return (a < b ? a = b, 1 : 0); } template<class T> bool minimize(T &a, const T &b) { return (a > b ? a = b, 1 : 0); } int dx[8] = {0, 1, 0,-1, 1, 1,-1,-1}; int dy[8] = {1, 0,-1, 0, 1,-1,-1, 1}; const int maxn = 2e3 + 9; const int Inf = 2e9 + 7; const ll Infll = 1e18 + 9; const ll Mod = 1e9 + 7; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ ll dp[maxn]; int n, s; vector<pll> b; void solve() { cin >> s >> n; for (int i=1; i<=n; i++) { int v, w, sl; cin >> v >> w >> sl; ll sum = 0; for (int i=0; sum + (1 << i) <= sl; i++) { b.pb({1ll * w * (1ll << i), 1ll * v * (1ll << i)}); sum += (1 << i); } if (sum < sl) { b.pb({1ll * w * (sl - sum), 1ll * v * (sl - sum)}); } } for (auto e : b) { for (int j=s; j>=e.fi; j--) { maximize(dp[j], dp[j-e.fi] + e.se); } } cout << dp[s]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); io("task"); solve(); return (0 ^ 0); }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:6:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define          io(x)   if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~
knapsack.cpp:56:5: note: in expansion of macro 'io'
   56 |     io("task");
      |     ^~
knapsack.cpp:6:85: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define          io(x)   if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
      |                                                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~
knapsack.cpp:56:5: note: in expansion of macro 'io'
   56 |     io("task");
      |     ^~
#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...