Submission #512294

#TimeUsernameProblemLanguageResultExecution timeMemory
512294KoDTenis (COCI20_tenis)C++17
110 / 110
63 ms5464 KiB
#include <bits/stdc++.h> using std::vector; using std::array; using std::pair; using std::tuple; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N; std::cin >> N; vector<array<int, 3>> order(N); vector<array<int, 3>> rank(N); for (int i = 0; i < 3; ++i) { for (int j = 0; j < N; ++j) { std::cin >> order[j][i]; order[j][i] -= 1; rank[order[j][i]][i] = j; } } array<int, 6> remain = {}; const auto add = [&](const int x, const int c) { array<int, 3> ord = {0, 1, 2}; int i = 0; do { if (std::is_sorted(ord.begin(), ord.end(), [&](const int i, const int j) { if (rank[x][i] != rank[x][j]) return rank[x][i] < rank[x][j]; return i < j; })) { remain[i] += c; break; } i += 1; } while (std::next_permutation(ord.begin(), ord.end())); }; for (int i = 0; i < N; ++i) { add(i, 1); } array<long long, 3> play = {}; vector<int> win(N); vector<char> done(N); const auto court = [&](const int i, const int j) { tuple tup(N, N, 3); for (int k = 0; k < 3; ++k) { tup = std::min(tup, tuple(std::min(rank[i][k], rank[j][k]), std::max(rank[i][k], rank[j][k]), k)); } return std::get<2>(tup); }; for (int i = 0; i < N; ++i) { std::map<int, vector<int>> here; for (int j = 0; j < 3; ++j) { const int x = order[i][j]; if (!done[x]) here[x].push_back(j); } for (const auto& [x, v] : here) { add(x, -1); done[x] = true; for (const auto& [y, u] : here) { if (x < y) { const int j = court(x, y); play[j] += 1; win[rank[x][j] < rank[y][j] ? x : y] += 1; } } } for (const auto& [x, v] : here) { array<int, 3> ord = {0, 1, 2}; int k = 0; do { for (const int j : ord) { if (std::binary_search(v.begin(), v.end(), j)) { play[j] += remain[k]; win[x] += remain[k]; break; } } k += 1; } while (std::next_permutation(ord.begin(), ord.end())); } } for (int i = 0; i < 3; ++i) { std::cout << play[i] << " \n"[i + 1 == 3]; } for (int i = 0; i < N; ++i) { std::cout << win[i] << " \n"[i + 1 == N]; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...