제출 #659024

#제출 시각아이디문제언어결과실행 시간메모리
659024evenvalue카니발 티켓 (IOI20_tickets)C++17
25 / 100
1774 ms178232 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template<typename T> using max_heap = priority_queue<T, vector<T>, less<T>>; using int64 = long long; using ld = long double; constexpr int kInf = 1e9 + 10; constexpr int64 kInf64 = 1e15 + 10; constexpr int kMod = 1e9 + 7; struct ticket { int value; int color; int index; bool operator<(const ticket &other) const { return value < other.value; } bool operator>(const ticket &other) const { return value > other.value; } }; int64 find_maximum(const int k, const vector<vector<int>> X) { const int n = (int) X.size(); //number of colours const int m = (int) X[0].size();//number of tickets vector<vector<ticket>> tickets(n, vector<ticket>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { tickets[i][j].value = X[i][j]; tickets[i][j].color = i; tickets[i][j].index = j; } } int64 ans = 0; max_heap<ticket> suff; vector<max_heap<ticket>> get_max(n); for (int i = 0; i < n; i++) { sort(tickets[i].begin(), tickets[i].end()); for (int j = 0; j < m; j++) { get_max[i].push(tickets[i][j]); } for (int j = 0; j < k; j++) { suff.push(tickets[i][j]); ans -= tickets[i][j].value; } } const int kChoose = n * k; assert(suff.size() == kChoose); vector<ticket> positive; while (suff.size() > kChoose / 2) { const auto x = suff.top(); suff.pop(); const auto y = get_max[x.color].top(); get_max[x.color].pop(); ans += x.value + y.value; positive.push_back(y); } assert(suff.size() == kChoose / 2); vector<ticket> negative; while (not suff.empty()) { const auto x = suff.top(); suff.pop(); negative.push_back(x); } sort(positive.begin(), positive.end(), [&](const ticket &t1, const ticket &t2) { return t1.color < t2.color; }); sort(negative.begin(), negative.end(), [&](const ticket &t1, const ticket &t2) { return t1.color < t2.color; }); vector<vector<int>> allocate(n, vector<int>(m, -1)); for (int i = 0, round = 0; i < kChoose / 2; i++, round = (round + 1) % k) { const ticket t1 = positive[i]; const ticket t2 = negative[i]; allocate[t1.color][t1.index] = round; allocate[t2.color][t2.index] = k - 1 - round; } allocate_tickets(allocate); return ans; }

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

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from tickets.cpp:2:
tickets.cpp: In function 'int64 find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:60:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<ticket, std::vector<ticket>, std::less<ticket> >::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   60 |   assert(suff.size() == kChoose);
      |          ~~~~~~~~~~~~^~~~~~~~~~
tickets.cpp:63:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<ticket, std::vector<ticket>, std::less<ticket> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |   while (suff.size() > kChoose / 2) {
      |          ~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from tickets.cpp:2:
tickets.cpp:73:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<ticket, std::vector<ticket>, std::less<ticket> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   73 |   assert(suff.size() == kChoose / 2);
      |          ~~~~~~~~~~~~^~~~~~~~~~~~~~
#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...