# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
659139 | evenvalue | 카니발 티켓 (IOI20_tickets) | C++17 | 1751 ms | 184664 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 group;
bool operator<(const ticket &other) const {
return value < other.value;
}
bool operator>(const ticket &other) const {
return value > other.value;
}
};
struct ticket_pair {
ticket one;
ticket two;
bool operator<(const ticket_pair &other) const {
return one.value + two.value < other.one.value + other.two.value;
}
bool operator>(const ticket_pair &other) const {
return one.value + two.value > other.one.value + other.two.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
const int choose = n * k; //number of tickets to choose
vector<vector<ticket>> tickets(n, vector<ticket>(m));
for (int color = 0; color < n; color++) {
for (int group = 0; group < m; group++) {
tickets[color][group].value = X[color][group];
tickets[color][group].color = color;
tickets[color][group].group = group;
}
}
vector<max_heap<ticket>> max_ticket(n);
for (int color = 0; color < n; color++) {
for (ticket &t : tickets[color]) {
max_ticket[color].push(t);
}
}
max_heap<ticket_pair> pq;
for (auto color : tickets) {
sort(color.begin(), color.end());
for (int i = 0; i < k; i++) {
pq.push({color[i], color[m - k + i]});
}
}
assert(pq.size() == choose);
vector<ticket> positive;
while (pq.size() > choose / 2) {
positive.push_back(pq.top().two);
pq.pop();
}
vector<ticket> negative;
while (not pq.empty()) {
negative.push_back(pq.top().one);
pq.pop();
}
assert(positive.size() == choose / 2);
assert(negative.size() == choose / 2);
sort(positive.begin(), positive.end(), [&](const ticket &t1, const ticket &t2)-> bool {
return t1.color < t2.color;
});
sort(negative.begin(), negative.end(), [&](const ticket &t1, const ticket &t2) -> bool {
return t1.color > t2.color;
});
int64 score = 0;
vector<vector<int>> s(n, vector<int>(m, -1));
for (int i = 0, r = 0; i < choose / 2; i++, r = (r + 1) % k) {
const ticket t1 = positive[i];
const ticket t2 = negative[i];
s[t1.color][t1.group] = r;
s[t2.color][t2.group] = r;
score += t1.value;
score -= t2.value;
}
allocate_tickets(s);
return score;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |