제출 #866373

#제출 시각아이디문제언어결과실행 시간메모리
866373phuxtrohhgKnapsack (NOI18_knapsack)C++14
17 / 100
2 ms604 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<ll, ll> #define st first #define nd second #define all(x) (x).begin(), (x).end() #define mp(x) make_pair(x) #define file "test" using namespace std; const double PI = 2 * acos(0); const long long INF = 1e18; const long long N = 2e6 + 5; ll s, n; ll dp[N]; vector<pii> w[2005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; for (int i = 1; i <=n; i++) { ll v, wai, k; cin >> v >> wai >> k; w[wai].push_back({v, k}); } for (int i = 1; i <= s; i++) { if (!w[i].size()) continue; sort(all(w[i]), greater<pii>()); ll curw = i; for (int r = 0; r < w[i].size(); r++) { if (curw > s) break; for (int sl = 1; sl <= w[i][r].nd; sl++, curw += i) for (int j = s; j >= i * sl; j--) dp[j] = max(dp[j], dp[j - i * sl] + w[i][r].st * sl); } // cout << i <<'\n'; // for (int i = 1; i <=s; i++) // cout << dp[i] <<' '; // cout << '\n'; } // for (int i = 1; i <=n; i++) // { // for (int j = 1; j <= s; j++) // cout << dp[i][j] <<' '; // cout << '\n'; // } cout << dp[s]; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:36:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             for (int r = 0; r < w[i].size(); r++)
      |                             ~~^~~~~~~~~~~~~
#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...