Submission #937519

#TimeUsernameProblemLanguageResultExecution timeMemory
937519WhisperKnapsack (NOI18_knapsack)C++17
73 / 100
1068 ms17692 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using str = string; using ld = long double; using T = tuple<ll, ll, ll>; #define int long long #define Base 31 #define sz(a) (int)a.size() #define FOR(i, a, b) for ( int i = a ; i <= b ; i++ ) #define FORD(i, a, b) for (int i = a; i >= b; i --) #define REP(i, n) for ( int i = 0 ; i < n ; ++i ) #define REPD(i, n) for ( int i = n - 1 ; ~(--i) ; ) #define all(x) x.begin() , x.end() #define pii pair<int , int> #define fi first #define se second #define Lg(x) 31 - __builtin_clz(x) constexpr ll LINF = (1ll << 62); constexpr int INF = (1ll << 30); constexpr int MAX = 2e5 + 5; constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void setupIO(){ #define name "Whisper" //Phu Trong from Nguyen Tat Thanh High School for gifted student srand(time(NULL)); cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr); // freopen(name".inp", "r", stdin); // freopen(name".out", "w", stdout); cout << fixed << setprecision(10); } int n, m; int f[MAX]; void Whisper(){ cin >> m >> n; vector<int> W, V; for (int i = 1 ; i <= n ; i++){ int w, v, a; cin >> v >> w >> a; int j = 0; while (a >= (1 << j)){ W.push_back(w * (1 << j)); V.push_back(v * (1 << j)); a -= (1 << j); j++; } if (a > 0){ W.push_back(a * w); V.push_back(a * v); } } n = sz(W); for (int i = 0 ; i < n ; i++){ for (int k = m ; k >= W[i]; k--){ f[k] = max(f[k], f[k - W[i]] + V[i]); } } cout << f[m]; } signed main(){ setupIO(); int Test = 1; // cin >> Test; for ( int i = 1 ; i <= Test ; i++ ){ Whisper(); if (i < Test) cout << '\n'; } }
#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...