제출 #1030507

#제출 시각아이디문제언어결과실행 시간메모리
1030507LmaoLmaoKnapsack (NOI18_knapsack)C++17
0 / 100
2 ms860 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using aa = array<int,3>; const int N = 1e6+5; const int INF = 1e9; ll dp[2005]; vector<ii> m[2005]; int pre[2005][2005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int n,s; cin >> s >> n; for(int i=1;i<=s;i++) { dp[i]=0; } dp[0]=0; for(int i=1;i<=n;i++) { int v,w,k; cin >> v >> w >> k; m[w].push_back({v,k}); } for(int i=1;i<=s;i++) { sort(m[i].begin(),m[i].end(),greater<>()); } for(int i=1;i<=s;i++) { int cur=0; for(ii x:m[i]) { int t=cur; cur+=x.second*i; cur=min(cur,s); for(int j=t+i;j<=cur;j+=i) { pre[i][j]=pre[i][j-i]+x.first; } if(cur>=s) break; } for(int j=1;j<=s;j++) pre[i][j]=max(pre[i][j],pre[i][j-1]); } ll ans=0; for(int i=1;i<=s;i++) { for(ll j=s;j>0;j--) { for(int k=1;i*k<=j;k++) { dp[j]=max(dp[j],dp[j-i*k]+pre[i][i*k]); ans=max(ans,dp[j]); } } } cout << ans; return 0; }

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

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