제출 #716408

#제출 시각아이디문제언어결과실행 시간메모리
716408BaytoroKnapsack (NOI18_knapsack)C++17
100 / 100
67 ms7348 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define endl '\n' #define ll long long #define int long long void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const ll INF=1e18,mod=1e9+7,N=2e5+5; int n,k; void solve(){ int s,n;cin>>s>>n; vector<pair<int,int>> g[2005]; vector<int> w(n+1),v(n+1),k(n+1); for(int i=1;i<=n;i++){ cin>>v[i]>>w[i]>>k[i]; g[w[i]].pb({v[i],k[i]}); } vector<int> dp(2005); for(int i=0;i<=s;i++){ if(g[i].size()==0) continue; sort(rall(g[i])); int id=0; for(int j=0;j*i<s;j++){ if(id>=(int)g[i].size()) break; for(int k=s;k-i>=0;k--){ dp[k]=max(dp[k],dp[k-i]+g[i][id].fr); } g[i][id].sc--; if(g[i][id].sc==0) id++; } } cout<<dp[s]; } main(){ //fopn("cbarn"); ios; int T=1; //cin>>T; for(int i=1;i<=T;i++){ //cout<<"Case #"<<i<<": "; solve(); } }

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

knapsack.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   42 | main(){
      | ^~~~
knapsack.cpp: In function 'void fopn(std::string)':
knapsack.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"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...