제출 #682635

#제출 시각아이디문제언어결과실행 시간메모리
682635vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
61 ms5008 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int mod = 1e9 + 7; const int maxn = 2010; typedef pair<int,int> ii; #define ff first #define ss second vector <ii> adj[maxn]; int n,S; int dp[maxn]; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>S>>n; for (int i=1; i<=n; i++) { int v,w,k; cin>>v>>w>>k; adj[w].push_back({v,k}); } for (int i=1; i<=S; i++) { if (adj[i].empty()) continue; sort(adj[i].begin(),adj[i].end(),greater<ii> ()); for (int j=S; j>=i; j--) { int it=0; int cnt = adj[i][it].ss; int temp=j; int w=0; while (it<adj[i].size()&&temp-i>=0) { temp-=i; w+=adj[i][it].ff; cnt--; dp[j]=max(dp[j],dp[temp]+w); if (cnt==0) { it++; cnt=adj[i][it].ss; } } } } cout<<dp[S]<<'\n'; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:32:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             while (it<adj[i].size()&&temp-i>=0)
      |                    ~~^~~~~~~~~~~~~~
#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...