제출 #660576

#제출 시각아이디문제언어결과실행 시간메모리
660576Ronin13Knapsack (NOI18_knapsack)C++14
100 / 100
172 ms36200 KiB
#include <bits/stdc++.h> #define ll long long #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back #define ull unsigned ll using namespace std; const int nmax = 3e5 + 1; int main(){ #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif // ONLINE_JUDGE int s, n; cin >> s >> n; pair<ll, pii> a[n + 1]; multiset <ll> st[s + 1]; for(int i = 1; i <= n; i++){ cin >> a[i].f >> a[i].s.f >> a[i].s.s; } sort(a + 1, a + 1 + n); reverse(a + 1, a + 1 + n); vector <vector <ll> > vec(s + 1); for(int i = 0; i <= s; i++) vec[i].pb(0); for(int i = 1; i <= n; i++){ int k = a[i].s.s, w = a[i].s.f; for(int j = 1; j <= k; j++){ if(vec[w].size() > 2000) break; vec[w].pb(vec[w].back() + a[i].f); } } ll dp[s + 1]; fill(dp, dp + s + 1, 0); dp[0] = 0; for(int i = 1; i <= s; i++){ for(int j = s; j >= 0; j--){ ll cnt = -1; for(int l = j; l >= 0; l -= i){ cnt++; if(cnt == vec[i].size()) break; dp[j] = max(dp[j], dp[l] + vec[i][cnt]); } } } ll mx = 0; for(int i = 1; i <= s; i++) mx = max(mx, dp[i]); cout << mx; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:45:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |                 if(cnt == vec[i].size()) break;
      |                    ~~~~^~~~~~~~~~~~~~~~
#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...