제출 #1059480

#제출 시각아이디문제언어결과실행 시간메모리
1059480vjudge1Knapsack (NOI18_knapsack)C++14
0 / 100
7 ms32092 KiB
/* Discord: powder7854 https://www.facebook.com/hai290605 https://codeforces.com/profile/Etohari https://oj.vnoi.info/user/powder */ #include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" //@Etohari using namespace std; using namespace __gnu_pbds; template < class T, class G > bool minimum(T& a, const G b) { return b < a ? a = b, 1 : 0; } template < class T, class G > bool maximum(T& a, const G b) { return a < b ? a = b, 1 : 0; } template < class T > using heap_min = priority_queue < T, vector < T >, greater < T > >; template < class T > using heap_max = priority_queue < T, vector < T >, less < T > >; template < class T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >; template < class T > using ordered_multiset = tree < T, null_type, less_equal < T >, rb_tree_tag, tree_order_statistics_node_update >; #define my_wife "Thu" #define bit(mask,i) ((mask>>i)&1) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define __lcm(a,b) ((int64_t)(a) / __gcd((a), (b)) * (b)) #define rand(l, r) uniform_int_distribution < int64_t > (l, r)(rng) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); constexpr int32_t MOD = 1e9 + 7; constexpr int32_t MAXN = 2e3 + 10; constexpr int32_t MAXM = 1e6 + 10; constexpr int32_t INF32 = 0x3f3f3f3f; constexpr int64_t INF64 = 0x3f3f3f3f3f3f3f3f; constexpr int16_t DR[] = { }; constexpr int16_t DC[] = { }; int n, s; int64_t dp[MAXN][MAXN]; vector < pair < int, int > > bag[MAXN]; signed main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> s >> n; for (int i = 1; i <= n; i ++) { int v, w, k; cin >> v >> w >> k; bag[w].emplace_back(v, k); } for (int w = 1; w < MAXN; w ++) { // O(s) auto& a = bag[w]; sort(rall(a)); for (int j = 0; j <= s; j ++) { // O(s) dp[w][j] = dp[w - 1][j]; int cost = 0, id = 0, c = 0, used = 0; while ((c + 1) * w <= j && id < a.size()) { // 1 / w, 2 / w, 3 / w, +.. + s / w cost += a[id].first; c ++; dp[w][j] = max(dp[w][j], dp[w - 1][j - c * w] + cost); used ++; if (used == a[id].second) { used = 0; id ++; } } } } cout << dp[n][s]; return (0 ^ 0); } /* Cho tới khi nào ? */

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:64:55: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |                         while ((c + 1) * w <= j && id < a.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...