Submission #947064

#TimeUsernameProblemLanguageResultExecution timeMemory
947064AkibAzmainCarnival Tickets (IOI20_tickets)C++17
11 / 100
2 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); vector < ll > a; 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; a.push_back (mn[i].first); a.push_back (mx[j].first); 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; a.push_back (mn[i].first); a.push_back (mx[ji].first); v[mn[i].second] = v[mx[ji].second] = true; } else { ans[mn[ii].second][0] = 0; ans[mx[j].second][m - 1] = 0; a.push_back (mn[ii].first); a.push_back (mx[j].first); v[mn[ii].second] = v[mx[j].second] = true; } } sort (a.begin (), a.end ()); for (auto &x : a) sum += abs (x - a[n / 2]); } 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...