제출 #486235

#제출 시각아이디문제언어결과실행 시간메모리
486235joshualiu555Knapsack (NOI18_knapsack)C++14
12 / 100
1 ms320 KiB
/* _____ _ _ / ____| | | | | | | __ _ __ __ _ ___ ___ _ _ _ __ ___ | |_ __ _| |_ ___ | | |_ | '__/ _` / __/ __| | | | '_ \ / _ \| __/ _` | __/ _ \ | |__| | | | (_| \__ \__ \ |_| | |_) | (_) | || (_| | || (_) | \_____|_| \__,_|___/___/\__, | .__/ \___/ \__\__,_|\__\___/ __/ | | |___/|_| */ #include <fstream> #include <iostream> #include <iomanip> #include <algorithm> #include <numeric> #include <utility> #include <array> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <cmath> #include <cstring> #include <climits> #include <bitset> #include <string> #include <sstream> using namespace std; #define FOR(i, x, s) for (int i = x; i < s; i++) #define TRAV(it, x) for (auto it = x.begin(); it != x.end(); it++) using ll = long long; const int INF = 2e5 + 5; const int MOD = 1e9 + 7; // DURL const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, 1, -1}; int S, N; map<int, vector<pair<int, int>>> weight_group; int dp[2005]; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); // ifstream cin(".in"); // ofstream cout(".out"); memset(dp, -1, sizeof(dp)); cin >> S >> N; for (int i = 0; i < N; i++) { int V, W, K; cin >> V >> W >> K; weight_group[W].push_back(make_pair(V, K)); } dp[0] = 0; for (auto it = weight_group.begin(); it != weight_group.end(); it++) { int weight = it -> first; // first = value, second = amount vector<pair<int, int>> items = it -> second; for (int i = S; i >= 0; i--) { if (dp[i] == -1) continue; int current = i; int id = 0; int left = items[id].second; while (current <= S) { if (id == items.size()) break; dp[current + weight] = max(dp[current + weight], dp[current] + items[id].first); left--; if (left == 0) { id++; left = items[id].second; } current += weight; } } } cout << *max_element(dp, dp + S + 1); return 0; } /* * */ //

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:74:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |                 if (id == items.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...