제출 #301276

#제출 시각아이디문제언어결과실행 시간메모리
301276Khongor카니발 티켓 (IOI20_tickets)C++14
41 / 100
1388 ms108776 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> ans; // 1 5 // 10 10 // 8 12 // 12 20 const int MAX = 1555; long long dp[MAX][MAX]; long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); ans = vector<vector<int>>(n, vector<int>(m, -1)); long long res = 0; vector<pair<int, pair<int, int>>> all; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) all.push_back({x[i][j], {i, j}}); sort(all.begin(), all.end()); vector<vector<pair<int, int>>> high(n), pickedLow(n), pickedHigh(n); int median = (all[n * m / 2].first + all[n * m / 2 - 1].first) / 2; int cnt = 0; for (int i = 0; i < all.size(); i++) { int color = all[i].second.first; int ticket = all[i].second.second; if (i < all.size() / 2) { if (pickedLow[color].size() < k) { pickedLow[color].push_back({median - all[i].first, ticket}); cnt++; res += median - all[i].first; } } else { high[color].push_back({all[i].first - median, ticket}); } } for (int i = 0; i < n; i++) { while (pickedLow[i].size() + pickedHigh[i].size() < k) { res += high[i].back().first; pickedHigh[i].push_back(high[i].back()); high[i].pop_back(); } } int need = cnt - n * k / 2; while (need--) { int idx = -1, best = 0; for (int i = 0; i < n; i++) { int cur; // assert(pickedLow[i].size() > 0 || high[i].size() > 0); if (high[i].empty() || pickedLow[i].empty()) continue; cur = high[i].back().first - pickedLow[i].back().first; if (idx == -1 || cur > best) { best = cur; idx = i; } } assert(idx != -1); // switch res += best; if (pickedLow[idx].size() > 0) pickedLow[idx].pop_back(); pickedHigh[idx].push_back(high[idx].back()); high[idx].pop_back(); } int cntNeg = 0, cntPos = 0; for (int i = 0; i < n; i++) { cntNeg += pickedLow[i].size(); cntPos += pickedHigh[i].size(); assert(pickedLow[i].size() + pickedHigh[i].size() == k); } assert(cntNeg + cntPos == n * k); assert(cntNeg == n * k / 2); for (int r = 0; r < k; r++) { vector<bool> used(n); vector<pair<int, int>> counts; for (int i = 0; i < n; i++) counts.push_back({pickedLow[i].size(), i}); sort(counts.rbegin(), counts.rend()); int taken = 0; for (int ii = 0; ii < n; ii++) { int i = counts[ii].second; if (pickedLow[i].size() > 0) { used[i] = true; taken++; ans[i][pickedLow[i].back().second] = r; pickedLow[i].pop_back(); } if (taken == n / 2) break; } taken = 0; for (int i = 0; i < n; i++) { if (pickedHigh[i].size() > 0 && !used[i]) { taken++; ans[i][pickedHigh[i].back().second] = r; pickedHigh[i].pop_back(); } if (taken == n / 2) break; } } allocate_tickets(ans); return res; } // a b a c // c b d d

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

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for (int i = 0; i < all.size(); i++) {
      |                  ~~^~~~~~~~~~~~
tickets.cpp:33:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   if (i < all.size() / 2) {
      |       ~~^~~~~~~~~~~~~~~~
tickets.cpp:34:32: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |    if (pickedLow[color].size() < k)  {
      |        ~~~~~~~~~~~~~~~~~~~~~~~~^~~
tickets.cpp:44:53: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |   while (pickedLow[i].size() + pickedHigh[i].size() < k) {
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from tickets.cpp:2:
tickets.cpp:80:53: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |   assert(pickedLow[i].size() + pickedHigh[i].size() == k);
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...