제출 #883822

#제출 시각아이디문제언어결과실행 시간메모리
883822PieArmyKnapsack (NOI18_knapsack)C++14
12 / 100
1 ms616 KiB
#include <bits/stdc++.h> typedef long long ll; #define yem(re) (1ll<<(ll(re))) #define endl '\n' #define pb push_back #define int long long #define mid ((left+right)/2) #define L(emanuelLasker,joseRaulCapablanca,anatolyKarpov) for(int emanuelLasker=(joseRaulCapablanca);emanuelLasker<=(anatolyKarpov);emanuelLasker++) #define R(magnusCarlsen,paulMorphy,bobbyFischer) for(int magnusCarlsen=(paulMorphy);magnusCarlsen>=(bobbyFischer);magnusCarlsen--) #define cint(vladimirKramnik) int vladimirKramnik;cin>>vladimirKramnik #define inf (2e18+5) #define sc second #define fr first #define Bismillahirrahmanirrahim ios_base::sync_with_stdio(false);cin.tie(NULL); #define cinarr(mikhailTal) for(auto &garryKasparov:mikhailTal)cin>>garryKasparov; #define all(mustafaKemalAtaturk) mustafaKemalAtaturk.begin(),mustafaKemalAtaturk.end() using namespace std; mt19937 rng(chrono::high_resolution_clock().now().time_since_epoch().count()); void code(){ int n,k;cin>>k>>n; vector<pair<int,pair<int,int>>>v; L(i,0,n-1){ cint(val);cint(cos);cint(num); v.pb({val,{cos,num}}); } sort(all(v)); vector<int>dp(k+1,-1); dp[0]=0; R(i,n-1,0){ vector<int>dp2(k+1,-1); int val=v[i].fr,cos=v[i].sc.fr,num=v[i].sc.sc; L(j,0,k)dp2[i]=dp[i]; L(j,0,k){ if(dp[j]==-1)continue; int x=min(ll((k-j)/cos),num); dp2[j+(x*cos)]=max(dp2[j+(x*cos)],dp[j]+(x*val)); } swap(dp2,dp); } int ans=0; for(int x:dp)ans=max(x,ans); cout<<ans; } int32_t main(){ Bismillahirrahmanirrahim int t=1; bool usaco=0; if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; } //Haven't checked tutorial yet...

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:51:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |               ~~~~~~~^~~~~~~~~~~~~~~~~
knapsack.cpp:51:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     if(usaco){freopen(".in","r",stdin);freopen(".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...