제출 #863113

#제출 시각아이디문제언어결과실행 시간메모리
863113sanoKnapsack (NOI18_knapsack)C++14
100 / 100
55 ms4824 KiB
#include <iostream> #include <string> #include <string.h> #include <fstream> #include <algorithm> #include <vector> #include <iomanip> #include <queue> #include<map> #include <stack> #include <unordered_map> #include <set> #define ll long long #define For(i, n) for(int i = 0; i < n; i++) #define pb push_back #define vec vector #define ff first #define ss second #define pairs pair<int, int> #define NEK 1000000000 #define PRI 1000000007 using namespace std; struct tr { int a; int b; int c; }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, s; cin >> s >> n; map<int, vec<pairs>> p; For(i, n) { int v, w, m; cin >> v >> w >> m; if (w <= s && m > 0) { p[w].push_back({ v, m }); } } vec<vec<int>> b(2, vec<int>(s + 1, 0)); int t2 = 1; for (auto e : p) { int now = t2 % 2; int last = 1 - now; auto a = e.first; vec<pairs> u = e.second; sort(u.begin(), u.end(), greater<pairs>()); for (int i = 0; i < s + 1; i++) { b[now][i] = b[last][i]; int poz = 0; int pen = 0; int kop = 0; int tkop = 0; while ((kop + 1) * a <= i && poz < u.size()) { kop++; pen = pen + u[poz].first; b[now][i] = max(b[now][i], b[last][i - kop * a] + pen); tkop++; if (tkop == u[poz].ss) { tkop = 0; poz++; } } } t2++; } cout << b[(t2-1)%2][s] << endl; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:58:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |    while ((kop + 1) * a <= i && poz < u.size()) {
      |                                 ~~~~^~~~~~~~~~
#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...