Submission #1097868

#TimeUsernameProblemLanguageResultExecution timeMemory
1097868ArtKnapsack (NOI18_knapsack)C++17
73 / 100
1074 ms17476 KiB
// |Art| - Bùi Hải Đăng K65 // // #pragma GCC optimize("02,unroll-loops") // #pragma GCC target("avx2,fma") #include <bits/stdc++.h> #define fi first #define se second #define el cout << '\n' #define sz(x) (x).size() #define all(v) (v).begin(), (v).end() #define debug(val) cout << "["#val" = " << (val) << "] " #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define REV(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define __Art__ main(void) const int N = 1e6 + 10; using namespace std; int s, n; vector<long long> w, v; void prepare() { cin >> s >> n; w.push_back(0); v.push_back(0); FOR (i, 1, n) { long long weg, val, num; cin >> val >> weg >> num; int pow2 = 1; while(num >= pow2) { w.push_back(weg * pow2); v.push_back(val * pow2); num -= pow2; pow2 *= 2; } if(num > 0) { w.push_back(weg * num); v.push_back(val * num); } } } // ---------------------------- // long long f[N]; // ---------------------------- // void solve() { int len = sz(w) - 1; FOR (i, 1, len) { long long weg = w[i], val = v[i]; REV (j, s, 0) if(j >= weg) { f[j] = max(f[j], f[j - weg] + val); } } cout << f[s], el; } __Art__ { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define name "art" if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } int numtest = 1; // cin >> numtest; while (numtest--) { prepare(); {solve(); continue;} } // cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; return 0; }

Compilation message (stderr)

knapsack.cpp:22:25: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | #define __Art__         main(void)
      |                         ^~~~
knapsack.cpp:73:1: note: in expansion of macro '__Art__'
   73 | __Art__ {
      | ^~~~~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(name".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...