Submission #1097875

#TimeUsernameProblemLanguageResultExecution timeMemory
1097875ArtKnapsack (NOI18_knapsack)C++17
100 / 100
763 ms8400 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 = 2e3 + 10; using namespace std; int s, n; vector<int> w; vector<int> v; void prepare() { cin >> s >> n; w.push_back(0); v.push_back(0); FOR (i, 1, n) { int weg, val, num; cin >> val >> weg >> num; int pow2 = 1; bool check = 1; while(num >= pow2) { if (weg > s / pow2) { check = 0; break; } w.push_back(weg * pow2); v.push_back(val * pow2); num -= pow2; pow2 *= 2; } if(num > 0 && check) { w.push_back(weg * num); v.push_back(val * num); } } } // ---------------------------- // long long f[N]; // ---------------------------- // void solve() { FOR (i, 1, sz(w) - 1) REV (j, s, w[i]) { f[j] = max(f[j], f[j - w[i]] + v[i]); } cout << f[s]; } __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:75:1: note: in expansion of macro '__Art__'
   75 | __Art__ {
      | ^~~~~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         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...