제출 #367293

#제출 시각아이디문제언어결과실행 시간메모리
367293NachoLibre카니발 티켓 (IOI20_tickets)C++17
100 / 100
945 ms71148 KiB
#include <bits/stdc++.h> using namespace std; #define sz(a) ((int)(a).size()) typedef vector<int> vint; typedef vector<vint> vvint; #ifndef wambule #include "tickets.h" #else void allocate_tickets(vvint a) { int n = a.size(); int m = a.begin()->size(); for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { cout << a[i][j] << " "; } cout << "\n"; } } #endif long long find_maximum(int k, vvint x) { int n = x.size(); int m = x.begin()->size(); vint v(n, 0); priority_queue<pair<int, int>> pq; long long dr = 0; for(int i = 0; i < n; ++i) { for(int j = 0; j < k; ++j) { dr -= x[i][j]; } pq.push({x[i][k - 1] + x[i][m - 1], i}); } for(int i = 0; i < n * k / 2; ++i) { int y = pq.top().second; dr += pq.top().first; pq.pop(); ++v[y]; if(v[y] < k) { pq.push({x[y][k - 1 - v[y]] + x[y][m - 1 - v[y]], y}); } } vector<pair<pair<int, int>, int>> u; for(int i = 0; i < n; ++i) { u.push_back({{k - 1 - v[i], m - v[i]}, i}); } vvint fp(n, vint(m, -1)); for(int i = 0; i < k; ++i) { sort(u.begin(), u.end()); for(int j = 0; j < n; ++j) { int y = 0; if(j < n / 2) { y = u[j].first.second++; } else { y = u[j].first.first--; } fp[u[j].second][y] = i; } } allocate_tickets(fp); return dr; } #ifdef wambule int main() { ios::sync_with_stdio(0); cin.tie(0); cout << find_maximum(2, {{0, 2, 5}, {1, 1, 3}}) << endl << endl; cout << find_maximum(1, {{5, 9}, {1, 4}, {3, 6}, {2, 7}}) << endl << endl; return 0; } #endif
#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...