Submission #900511

#TimeUsernameProblemLanguageResultExecution timeMemory
900511nguyentunglamCarnival Tickets (IOI20_tickets)C++17
100 / 100
514 ms76276 KiB
#include<bits/stdc++.h> #include "tickets.h" #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; #ifdef ngu void allocate_tickets(vector<vector<int> > x) { for(auto &i : x) { for(auto &j : i) cout << j << " "; cout << endl; } } #endif // ngu long long find_maximum (int k, vector<vector<int> > x) { int n = x.size(); int m = x[0].size(); vector<int> l(n + 2), r(n + 2); vector<vector<int> > answer(n, vector<int> (m)); long long ans = 0; priority_queue<pair<int, int> > q; for(int i = 0; i < n; i++) { l[i] = k - 1; r[i] = m - 1; for(int j = 0; j < k; j++) ans -= x[i][j]; q.push({x[i][r[i]] + x[i][l[i]], i}); } for(int loop = 1; loop <= n / 2 * k; loop++) { assert(q.size() >= 1); int cost, i; tie(cost, i) = q.top(); q.pop(); ans += cost; l[i]--; r[i]--; if (l[i] >= 0) q.push({x[i][r[i]] + x[i][l[i]], i}); } vector<int> order(n); for(int i = 0; i < n; i++) { r[i]++; order[i] = i; } int mn = 1e9, mx = -1e9; for(int i = 0; i < n; i++) { if (l[i] >= 0) mx = max(mx, x[i][l[i]]); if (r[i] < m) mn = min(mn, x[i][r[i]]); } assert(mx <= mn); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) answer[i][j] = -1; for(int round = 0; round < k; round++) { sort(order.begin(), order.begin() + n, [&] (const int &x, const int &y) { return r[x] < r[y]; }); for(int cur = 0; cur < n / 2; cur++) { int i = order[cur]; assert(r[i] < m); answer[i][r[i]] = round; r[i]++; } for(int cur = n / 2; cur < n; cur++) { int i = order[cur]; assert(l[i] >= 0); answer[i][l[i]] = round; l[i]--; } } allocate_tickets(answer); return ans; } #ifdef ngu int main() { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); int n, m, k; cin >> n >> m >> k; vector<vector<int> > x(n, vector<int> (m)); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> x[i][j]; cout << find_maximum(k, x); } #endif // ngu
#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...