제출 #486247

#제출 시각아이디문제언어결과실행 시간메모리
486247joshualiu555Knapsack (NOI18_knapsack)C++14
100 / 100
407 ms4976 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}; ll S, N; map<ll, vector<pair<ll, ll>>> weight_group; ll dp[2005]; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); // ifstream cin(".in"); // ofstream cout(".out"); cin >> S >> N; for (ll i = 0; i < N; i++) { ll V, W, K; cin >> V >> W >> K; weight_group[W].push_back(make_pair(V, K)); } for (ll i = 0; i <= S; i++) { if (weight_group[i].empty()) continue; sort(weight_group[i].rbegin(), weight_group[i].rend()); ll id = 0; ll current = i; ll left = weight_group[i][id].second; while (current <= S) { if (id == weight_group[i].size()) break; for (ll j = S; j >= i; j--) { dp[j] = max(dp[j], dp[j - i] + weight_group[i][id].first); } left--; if (left == 0) { id++; left = weight_group[i][id].second; } current += i; } } cout << dp[S]; return 0; } /* * */ //

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

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