제출 #1097412

#제출 시각아이디문제언어결과실행 시간메모리
1097412NEMO_Knapsack (NOI18_knapsack)C++17
100 / 100
39 ms7428 KiB
#include <bits/stdc++.h> #define ll long long #define FAST \ ios::sync_with_stdio(false); \ cin.tie(NULL); #define ld long double #define pb(x) push_back(x) #define set(arr, x) memset(arr, x, sizeof(arr)) #define F0R(i, a) for (int i = 0; i < a; i++) #define F1R(i, a) for (int i = 1; i <= a; i++) #define all(x) (x).begin(), (x).end() #define loopi(x, n) for (long long i = x; i < n; ++i) #define loopj(x, n) for (long long j = x; j < n; ++j) #define yes \ cout << "YES\n"; \ return; #define no \ cout << "NO\n"; \ return; // vec.resize(unique(all(vec)) - vec.begin()); // iota(p.begin(), p.end(), 0); using namespace std; const int V = 1e6 + 7; const int N = 1e5 + 7; const int S = 2e3 + 7; const int inf = 1e9; ll s, n, v[N], w[N], k[N]; void solve() { cin >> s >> n; for (int i = 1; i <= n; i++) { cin >> v[i] >> w[i] >> k[i]; } int mxK = *max_element(k, k + n); if (1 <= n && n <= 1e5 && mxK <= 1e9) { vector<pair<ll, ll>> obj[S]; ll dp[2001]; memset(dp, 0, sizeof dp); for (int i = 1; i <= n; i++) { obj[w[i]].push_back({v[i], k[i]}); } for (int i = 0; i <= s; i++) { if (obj[i].size() <= 0) continue; sort(all(obj[i]), greater<pair<ll, ll>>()); int id = 0; for (int j = 0; j * i < s; j++) { if (obj[i].size() <= id) break; for (int k = s; k >= i; k--) { dp[k] = max(dp[k], dp[k - i] + obj[i][id].first); } --obj[i][id].second; if (obj[i][id].second == 0) ++id; } } cout << dp[s] << endl; } } int main() { FAST // freopen("time.in", "r", stdin); // freopen("time.out", "w", stdout); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:57:23: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |     if (obj[i].size() <= id)
      |         ~~~~~~~~~~~~~~^~~~~
#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...