Submission #647915

#TimeUsernameProblemLanguageResultExecution timeMemory
647915thegamercoder19Knapsack (NOI18_knapsack)C++14
73 / 100
908 ms262144 KiB
/* Coded by thegamercoder Happy Competition and Hacking */ /* pragma GCC optimize("O3") pragma GCC optimize("Ofast, unroll-loops") pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2") */ #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #define M_PI 3.14159265358979323846 #define FILER 0 using ll = long long; using ull = unsigned long long; using ld = long double; const ll MOD = pow(10, 9) + 7; const ll INFL = 0x3f3f3f3f3f3f3f3f; const ull INFUL = 0x3f3f3f3f3f3f3f3f; const ll INFT = 0x3f3f3f3f; const ll MAX = 1e7 + 1; const ll MODD = 998244353; const double EPS = 1e-10; #define V vector #define pll pair<ll, ll> #define pull2 pair<ull,ull> #define MS multiset #define M map #define Q queue #define PQ priority_queue #define IOF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define FOR(typ,i,a,b,c) for(typ i = a; i < b; i += c) #define FORR(typ,i,a,b,c) for(typ i = a; i > b; i -= c) #define FORA(a,i) for(auto &i : a) #define all(v) v.begin(),v.end() #define sz(v) v.size() #define sorta(a) sort(all(a)) #define sortd(a) sort(all(a), greater<ll>()) #define setp(x) setprecision(x)<<fixed #define RET return #define log(a,b) log(b)/log(a) #define WH(s) while(s) #define WHI(t) WH(t--) #define YES cout<<"YES"<<endl; #define NO cout<<"NO"<<endl; #define Yes cout<<"Yes"<<endl; #define No cout<<"No"<<endl; #define YESNO(s) cout<<(s?"YES":"NO")<<endl; #define YesNo(s) cout<<(s?"Yes":"No")<<endl; #define TYP 0 using namespace std; ll n,w; V<V<ll>> dp; V<ll>v, ww, k; void solve() { cin >> w >> n; dp.resize(n + 1, V<ll>(w + 1, 0)); v.resize(n + 1); ww.resize(n + 1); k.resize(n + 1); FOR(ll, i, 1, n + 1, 1)cin >> v[i] >> ww[i] >> k[i];// , k[i] = min(k[i], w / ww[i]); FOR(ll, i, 1, n + 1, 1) FOR(ll, j, 1, w + 1, 1) { dp[i][j] = dp[i - 1][j]; FOR(ll, q, 1, min(k[i], j / ww[i]) + 1, 1) dp[i][j] = max({ dp[i][j],dp[i - 1][j - q * ww[i]] + q * v[i],dp[i - 1][j] }); } cout << dp[n][w] << endl; } void init() { if (FILER) { freopen("feast.in", "r", stdin); freopen("feast.out", "w", stdout); } } void handle(bool f) { init(); if (f) { ll t; cin >> t; WHI(t)solve(); return; } solve(); } int main() { IOF handle(TYP); RET 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void init()':
knapsack.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen("feast.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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("feast.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...