Submission #947056

#TimeUsernameProblemLanguageResultExecution timeMemory
947056AkibAzmainCarnival Tickets (IOI20_tickets)C++17
11 / 100
1 ms604 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; using ll = long long; long long find_maximum(int k, std::vector<std::vector<int>> arr) { ll n = arr.size(); ll m = arr[0].size(); std::vector<std::vector<int>> ans (n, vector < int > (m, -1)); ll sum = 0; if (k == 1) { vector < pair < ll, ll > > mn (n), mx (n); for (int i = 0; i < n; ++i) { mn[i] = { arr[i][0], i }; mx[i] = { arr[i][m - 1], i }; } sort (mn.begin (), mn.end ()); sort (mx.begin (), mx.end ()); reverse (mx.begin (), mx.end ()); int i = 0, j = 0; vector < bool > v (n); for (int k = 0; k < n / 2; ++k) { while (v[mn[i].second]) ++i; while (v[mx[j].second]) ++j; if (mn[i].second != mx[j].second) { ans[mn[i].second][0] = 0; ans[mx[j].second][m - 1] = 0; sum += mx[j].first - mn[i].first; assert (!v[mn[i].second]); assert (!v[mx[j].second]); v[mn[i].second] = v[mx[j].second] = true; continue; } int ii = i + 1; int ji = j + 1; while (ii < n && v[mn[ii].second]) ++ii; while (ji < n && v[mx[ji].second]) ++ji; if (ji < n && mx[ji].first - mn[i].first > mx[j].first - mn[ii].first) { ans[mn[i].second][0] = 0; ans[mx[ji].second][m - 1] = 0; sum += mx[ji].first - mn[i].first; assert (!v[mn[i].second]); assert (!v[mx[ji].second]); v[mn[i].second] = v[mx[ji].second] = true; } else { ans[mn[ii].second][0] = 0; ans[mx[j].second][m - 1] = 0; sum += mx[j].first - mn[ii].first; assert (!v[mn[ii].second]); assert (!v[mx[j].second]); v[mn[ii].second] = v[mx[j].second] = true; } } for (auto x : v) assert (x); } allocate_tickets(ans); return sum; }
#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...