Submission #883780

#TimeUsernameProblemLanguageResultExecution timeMemory
883780vjudge1Knapsack (NOI18_knapsack)C++17
37 / 100
1 ms604 KiB
// Goten2308 #include<bits/stdc++.h> using namespace std; //#define int long long using ll = long long; using ii = pair <int, int>; #define fi first #define se second #define mp(x, y) make_pair(x, y) #define pb(x) push_back(x) #define all(x) (x).begin(), (x).end() //#define endl '\n' #define BIT(x, y) ((x >> y) & 1) #define MASK(x) (1 << x) #define MOD 1000000007 #define MULTI_TEST1 template <class T> bool maximize(T& a, T b) { if(a < b) { a = b; return true; } return false; } template <class T> bool minimize(T& a, T b) { if(a > b) { a = b; return true; } return false; } template <class T> void add(T& a, T b) { a += b; if(a >= MOD) a -= MOD; } template <class T> void sub(T& a, T b) { a -= b; if(a <= 0) a += MOD; } void solve() { int n, s; cin >> s >> n; vector<ll> w, v; vector<ll> f(s + 1, 0ll); for(int i = 1; i <= n; i++) { int a, b, c; cin >> a >> b >> c; int cnt = 1; while(c - cnt >= 0) { w.pb(b * cnt); v.pb(a * cnt); c -= cnt; cnt *= 2; } if(c) { w.pb(b * c); v.pb(a * c); } } for(int i = 0; i < w.size(); i++) { for(int j = s; j >= w[i]; j--) { maximize(f[j], f[j - w[i]] + v[i]); } } cout << f[s] << endl; } signed main(){ #define task "" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } if(fopen("task.inp", "r")){ freopen("task.inp", "r", stdin); //freopen("task.out", "w", stdout); } cin.tie(0)->ios_base::sync_with_stdio(0); int nTest = 1; #ifdef MULTI_TEST cin >> nTest; #endif while(nTest--) solve(); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i = 0; i < w.size(); i++) {
      |                    ~~^~~~~~~~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...