Submission #1182242

#TimeUsernameProblemLanguageResultExecution timeMemory
1182242M0stafaKnapsack (NOI18_knapsack)C++20
73 / 100
779 ms327680 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("avx2") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define int long long using namespace std; #define all(x) x.begin(), x.end() typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> oset; template<typename T> bool smin(T& a, const T& b) { if (b < a) { a = b; return true; } return false;} template<typename T> bool smax(T& a, const T& b) { if (a < b) { a = b; return true; } return false;} template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &a){return out << a.first << " " << a.second;} template<typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x: v) in >> x; return in; } template<typename T>ostream &operator<<(ostream &out, const vector<T> &v) { for (const T &x: v) out << x << ' ';return out;} template <class K, class V> using ht = gp_hash_table<K, V, hash<K>, equal_to<K>, direct_mask_range_hashing<>, linear_probe_fn<>, hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<>, true>>; #ifndef ONLINE_JUDGE #define dout(...) cerr << "Line:" << __LINE__ << " [" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__) #else #define dout(...) #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int gen_random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } void pbit(int a) { cout << a << " : " << bitset<40>(a) << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int s, n; cin >> s >> n; vector<int> v(n), w(n), k(n); for (int i = 0; i < n; i++) { cin >> v[i] >> w[i] >> k[i]; } vector<vector<int>> dp(n + 1, vector<int>(s + 1, -1)); function<int(int, int)> f = [&](int i, int W) -> int { if (i >= n) return 0; if (dp[i][W] != -1) return dp[i][W]; int ans = f(i + 1, W); for (int j = 1; j <= k[i]; j++) { if (W - j * w[i] < 0) break; ans = max(ans, j * v[i] + f(i + 1, W - j * w[i])); } return dp[i][W] = ans; }; cout << f(0, s); return 0; }

Compilation message (stderr)

knapsack.cpp:2:28: warning: bad option '-favx2' to pragma 'optimize' [-Wpragmas]
    2 | #pragma GCC optimize("avx2")
      |                            ^
knapsack.cpp:12:48: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   12 | template<typename T> bool smin(T& a, const T& b) { if (b < a) { a = b; return true; } return false;}
      |                                                ^
knapsack.cpp:13:48: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   13 | template<typename T> bool smax(T& a, const T& b) { if (a < b) { a = b; return true; } return false;}
      |                                                ^
knapsack.cpp:14:82: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   14 | template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &a){return out << a.first << " " << a.second;}
      |                                                                                  ^
knapsack.cpp:15:67: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   15 | template<typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x: v) in >> x; return in; }
      |                                                                   ^
knapsack.cpp:16:73: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   16 | template<typename T>ostream &operator<<(ostream &out, const vector<T> &v) { for (const T &x: v) out << x << ' ';return out;}
      |                                                                         ^
knapsack.cpp:25:35: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   25 | inline int gen_random(int l, int r) {
      |                                   ^
knapsack.cpp:28:16: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   28 | void pbit(int a) {
      |                ^
knapsack.cpp:31:13: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   31 | signed main() {
      |             ^
knapsack.cpp: In function 'int main()':
knapsack.cpp:8:18: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
    8 | #define int long long
      |                  ^~~~
knapsack.cpp:43:54: note: in expansion of macro 'int'
   43 |     function<int(int, int)> f = [&](int i, int W) -> int {
      |                                                      ^~~
#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...