제출 #425246

#제출 시각아이디문제언어결과실행 시간메모리
425246peijar카니발 티켓 (IOI20_tickets)C++17
100 / 100
1066 ms92152 KiB
#include <bits/stdc++.h> using namespace std; #include "tickets.h" long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> answer(n, vector<int>(m, -1)); vector<vector<int>> side(n, vector<int>(m, -1)); vector<tuple<int, int, int>> swaps; long long sol = 0; for (int i = 0; i < n; ++i) { for (int j(0); j < k; ++j) { int other = m - k + j; sol -= x[i][j]; side[i][j] = 0; swaps.emplace_back(x[i][j] + x[i][other], i, j); } } sort(swaps.rbegin(), swaps.rend()); for (int a(0); a < n * k / 2; ++a) { auto [delta, i, j] = swaps[a]; int other = m - k + j; sol += delta; side[i][j] = -1; side[i][other] = 1; } vector<vector<int>> posLeft(n), posRight(n); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { if (side[i][j] == 1) posRight[i].push_back(j); else if (side[i][j] == 0) posLeft[i].push_back(j); } for (int round = 0; round < k; ++round) { vector<bool> picked(n); int gaucheNec = n / 2, droiteNec = n / 2; for (int col = 0; col < n; ++col) { if (posLeft[col].empty()) { picked[col] = true; answer[col][posRight[col].back()] = round; posRight[col].pop_back(); droiteNec--; } else if (posRight[col].empty()) { picked[col] = true; answer[col][posLeft[col].back()] = round; posLeft[col].pop_back(); gaucheNec--; } } for (int col = 0; col < n; ++col) { if (picked[col]) continue; assert(!posLeft[col].empty() and !posRight[col].empty()); if (gaucheNec > 0) { answer[col][posLeft[col].back()] = round; posLeft[col].pop_back(); gaucheNec--; } else { assert(droiteNec > 0); answer[col][posRight[col].back()] = round; posRight[col].pop_back(); droiteNec--; } } } allocate_tickets(answer); return sol; }
#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...