제출 #406056

#제출 시각아이디문제언어결과실행 시간메모리
406056tiberiu카니발 티켓 (IOI20_tickets)C++14
100 / 100
1124 ms92712 KiB
#include "tickets.h" #include <vector> #include <algorithm> #include <iostream> #include <queue> #include <set> using namespace std; typedef pair<int, int> pii; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> ans = vector<vector<int>>(n, vector<int>(m, -1)); deque<pii> unused[n], mins[n], maxs[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) unused[i].push_back({x[i][j], j}); sort(unused[i].begin(), unused[i].end()); } priority_queue<pii> best; long long win = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { // cerr << "Unused: " << unused[i].begin()->first << endl; win -= unused[i].begin()->first; mins[i].push_back(*unused[i].begin()); unused[i].pop_front(); } best.push({mins[i].rbegin()->first + (unused[i].size() ? unused[i].rbegin()->first : mins[i].rbegin()->first), i}); // cerr << "Inserted: " << mins[i].rbegin()->first << endl; } for (int ix = 0; ix < k * n / 2; ix++) { pii b = best.top(); best.pop(); win += b.first; int c = b.second; // cerr << b.first << endl; if (unused[c].size()) { maxs[c].push_front(*unused[c].rbegin()); unused[c].pop_back(); unused[c].push_front(*mins[c].rbegin()); } else { maxs[c].push_front(*mins[c].rbegin()); } mins[c].pop_back(); if (mins[c].size()) { best.push({mins[c].rbegin()->first + (unused[c].size() ? unused[c].rbegin()->first : mins[c].rbegin()->first), c}); } } for (int r = 0; r < k; r++) { vector<pii> c; for (int j = 0; j < n; j++) { c.push_back({maxs[j].size(), j}); // cout << c.back().first << ' '; } // cout << endl; sort(c.begin(), c.end()); for (int i = 0; i < n / 2; i++) { int col = c[i].second; int ix = mins[col].begin()->second; ans[col][ix] = r; mins[col].pop_front(); } for (int i = n / 2; i < n; i++) { int col = c[i].second; int ix = maxs[col].begin()->second; ans[col][ix] = r; maxs[col].pop_front(); } } allocate_tickets(ans); return win; }
#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...