Submission #1094924

#TimeUsernameProblemLanguageResultExecution timeMemory
1094924rayan_bdKnapsack (NOI18_knapsack)C++17
100 / 100
161 ms35664 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optimize("-fpeephole2") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-fsched-spec") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-falign-jumps") #pragma GCC optimize("-falign-loops") #pragma GCC optimize("-falign-labels") #pragma GCC optimize("-fdevirtualize") #pragma GCC optimize("-fcaller-saves") #pragma GCC optimize("-fcrossjumping") #pragma GCC optimize("-fthread-jumps") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-fwhole-program") #pragma GCC optimize("-freorder-blocks") #pragma GCC optimize("-fschedule-insns") #pragma GCC optimize("inline-functions") #pragma GCC optimize("-ftree-tail-merge") #pragma GCC optimize("-fschedule-insns2") #pragma GCC optimize("-fstrict-aliasing") #pragma GCC optimize("-fstrict-overflow") #pragma GCC optimize("-falign-functions") #pragma GCC optimize("-fcse-skip-blocks") #pragma GCC optimize("-fcse-follow-jumps") #pragma GCC optimize("-fsched-interblock") #pragma GCC optimize("-fpartial-inlining") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("-freorder-functions") #pragma GCC optimize("-findirect-inlining") #pragma GCC optimize("-fhoist-adjacent-loads") #pragma GCC optimize("-frerun-cse-after-loop") #pragma GCC optimize("inline-small-functions") #pragma GCC optimize("-finline-small-functions") #pragma GCC optimize("-ftree-switch-conversion") #pragma GCC optimize("-foptimize-sibling-calls") #pragma GCC optimize("-fexpensive-optimizations") #pragma GCC optimize("-funsafe-loop-optimizations") #pragma GCC optimize("inline-functions-called-once") #pragma GCC optimize("-fdelete-null-pointer-checks") #define ll long long #define pb push_back #define all(v) v.begin(), v.end() const ll N_INF = -1e9; const int mxN = 2005; int N,S; vector<pair<int,int>> itm[mxN]; vector<vector<ll>> dp(mxN,vector<ll>(mxN,-1)); ll f(int i,int tot){ if(tot<0) return N_INF; if(i==S+1) return 0; if(dp[i][tot]!=-1) return dp[i][tot]; ll ans=max(f(i+1,tot),0ll); ll taken_w=0,taken_p=0; for(auto it:itm[i]){ ll p=it.first,c=it.second; while(c>0){ taken_w+=i,taken_p+=p,--c; if(tot-taken_w<0){ taken_w=-1; break; } ans=max(ans,f(i+1,tot-taken_w)+taken_p); } if(taken_w==-1) break; } return dp[i][tot]=ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int p,w,c;cin>>S>>N; // price,weight,copy for(ll i=0;i<N;++i){ cin>>p>>w>>c; if(w<=S&&c>0) itm[w].pb({p,c}); } for(ll i=0;i<=2001;++i) sort(all(itm[i]),greater<pair<ll,ll>>()); cout<<f(0,S); return 0; }

Compilation message (stderr)

knapsack.cpp:24:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   24 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
knapsack.cpp:31:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   31 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
knapsack.cpp:33:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   33 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
knapsack.cpp:47:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   47 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
knapsack.cpp:63:19: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   63 | ll f(int i,int tot){
      |                   ^
knapsack.cpp:63:19: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
knapsack.cpp:63:19: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
knapsack.cpp:63:19: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
knapsack.cpp:85:10: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   85 | int main() {
      |          ^
knapsack.cpp:85:10: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
knapsack.cpp:85:10: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
knapsack.cpp:85:10: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
#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...