제출 #490673

#제출 시각아이디문제언어결과실행 시간메모리
490673CyberSleeperKnapsack (NOI18_knapsack)C++14
100 / 100
57 ms3916 KiB
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl #define fi first #define se second #define mp make_pair #define pb push_back #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define ar3 array<int, 3> #define nl '\n' #define tb '\t' #define sp ' ' using namespace std; const int MX=100005, MOD=1e9+7, BLOCK=500, INF=2e9+7; const ll INFF=1e18+7; const ld ERR=1e-7, pi=3.14159265358979323846; int S, N, DP[2][2005]; vector<pii> A[MX]; int main(){ fastio; cin >> S >> N; for(int i=1, v, w, k; i<=N; i++){ cin >> v >> w >> k; A[w].pb({v, k}); } for(int i=1; i<=S; i++) DP[0][i]=-INF; DP[0][0]=0; for(int i=1; i<=S; i++){ sort(A[i].begin(), A[i].end(), greater<pii>()); int now=i%2, bef=now^1; for(int j=1; j<=S; j++) DP[now][j]=-INF; DP[now][0]=0; for(int j=0; j<=S; j++){ int skor=DP[bef][j], idx=0, used=0, slot=j; while((idx<A[i].size()) && (i+slot)<=S){ skor+=A[i][idx].fi; slot+=i; DP[now][slot]=max(DP[now][slot], skor); used++; if(used>=A[i][idx].se){ idx++; used=0; } } DP[now][j]=max(DP[bef][j], DP[now][j]); } } N%=2; for(int i=0; i<S; i++) DP[S%2][S]=max(DP[S%2][S], DP[S%2][i]); cout << DP[S%2][S] << nl; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             while((idx<A[i].size()) && (i+slot)<=S){
      |                    ~~~^~~~~~~~~~~~
#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...