제출 #926911

#제출 시각아이디문제언어결과실행 시간메모리
926911haru09Knapsack (NOI18_knapsack)C++17
100 / 100
50 ms66456 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define task "code" const int ar=2e3+5; const ll mod=1e9+7; int n,s; vector<pair<int,int>> w[ar]; ll dp[ar][ar]; ll sum[ar][ar]; int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); if (fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin>>s>>n; for (int i=1;i<=n;i++) { int v,c,k; cin>>v>>c>>k; w[c].push_back({v,k}); } for (int i=1;i<=s;i++) { sort(w[i].begin(),w[i].end(),greater<pair<int,int>>()); sum[i][0]=0; int j=1; for (auto [v,k]:w[i]) { int last=j; while(i*j<=s && j-last<k) { sum[i][i*j]=sum[i][i*(j-1)]+v; j++; } } } for (int i=1;i<=s;i++) { for (int j=1;j<=s;j++) dp[i][j]=dp[i-1][j]; for (int j=i;j<=s;j+=i) { for (int k=j;k<=s;k++) { dp[i][k]=max(dp[i][k],dp[i-1][k-j]+sum[i][j]); } } } ll ans=0; for (int i=1;i<=s;i++) ans=max(ans,dp[s][i]); cout<<ans; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(task".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...