| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 335694 | aanastasov | Carnival Tickets (IOI20_tickets) | C++17 | 863 ms | 73268 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#define DEBUG(x) 42; //std::cerr << #x << ": " << x << std::endl;
template<typename T> void debugVector(std::vector<T> vals, bool skip = true) {
if (skip) return;
std::cerr << "{";
for (int i = 0; i < vals.size(); ++i) {
if (i > 0) std::cerr << ", ";
std::cerr << vals[i];
}
std::cerr << "}" << std::endl;
}
long long find_maximum(int numRounds, std::vector<std::vector<int>> ticket) {
const int numColors = ticket.size();
DEBUG(numColors);
const int length = ticket[0].size();
DEBUG(length);
// assert(numRounds == 1);
auto answer = std::vector<std::vector<int>>(numColors, std::vector<int>(length, -1));
auto minimums = std::vector<int>(numColors, 0);
auto maximums = std::vector<int>(numColors, length - 1);
auto chooseTickets = [&](int colorOfB, bool isMin) -> std::pair<bool, std::vector<int>> {
DEBUG(colorOfB);
DEBUG(isMin);
const int b = (isMin ? ticket[colorOfB][minimums[colorOfB]] : ticket[colorOfB][maximums[colorOfB]]);
DEBUG(b);
auto ticketsChosen = std::vector<int>(numColors, -1);
ticketsChosen[colorOfB] = b;
int numSmaller = 0;
int numLarger = 0;
auto choices = std::vector<std::pair<int, int>>();
for (int color = 0; color < numColors; ++color) {
assert(minimums[color] <= maximums[color]);
if (color == colorOfB) continue;
if (ticket[color][maximums[color]] < b) {
numSmaller++;
ticketsChosen[color] = ticket[color][minimums[color]];
} else if (b < ticket[color][minimums[color]]) {
numLarger++;
ticketsChosen[color] = ticket[color][maximums[color]];
} else {
long long minScore = llabs(ticket[color][minimums[color]] - b);
long long maxScore = llabs(ticket[color][maximums[color]] - b);
choices.push_back({maxScore - minScore, color});
}
}
debugVector(ticketsChosen);
DEBUG(numLarger);
DEBUG(numSmaller);
std::sort(choices.begin(), choices.end());
if (numLarger > numColors / 2 || numSmaller > numColors / 2 - 1) {
return {false, std::vector<int>()};
}
int index = choices.size() - 1;
while (numLarger < numColors / 2) {
auto item = choices[index];
index--;
ticketsChosen[item.second] = ticket[item.second][maximums[item.second]];
numLarger++;
}
assert(numLarger == numColors / 2);
while (index >= 0) {
auto item = choices[index];
ticketsChosen[item.second] = ticket[item.second][minimums[item.second]];
index--;
numSmaller++;
}
assert(numSmaller == numColors / 2 - 1);
for (auto x : ticketsChosen) assert(x != -1);
return {true, ticketsChosen};
};
auto evaluate = [](int b, std::vector<int>& chosenTickets) -> long long {
long long res = 0;
for (auto &x : chosenTickets) res += llabs(b - x);
return res;
};
long long totalScore = 0;
for (int round = 0; round < numRounds; ++round) {
auto bestB = std::pair<int, bool>(-1, false);
auto bestScore = -1LL;
for (int isMin = 0; isMin <= 1; ++isMin)
for (int color = 0; color < numColors; ++color) {
auto output = chooseTickets(color, isMin > 0 ? true : false);
DEBUG(output.first);
if (!output.first) continue;
const int b = isMin > 0 ? ticket[color][minimums[color]] : ticket[color][maximums[color]];
// std::cerr << "if we choose b = " << b << ": "; debugVector(output.second);
auto score = evaluate(b, output.second);
if (score > bestScore) {
bestScore = score;
bestB = {color, isMin > 0 ? true : false};
}
}
assert(bestScore >= 0);
totalScore += bestScore;
auto output = chooseTickets(bestB.first, bestB.second);
assert(output.first);
for (int color = 0; color < numColors; ++color) {
if (output.second[color] == ticket[color][minimums[color]]) {
answer[color][minimums[color]] = round;
minimums[color]++;
} else {
answer[color][maximums[color]] = round;
maximums[color]--;
}
}
}
allocate_tickets(answer);
return totalScore;
}
컴파일 시 표준 에러 (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... | ||||
