Submission #483315

#TimeUsernameProblemLanguageResultExecution timeMemory
483315lukaszgnieckiCarnival Tickets (IOI20_tickets)C++17
11 / 100
1 ms716 KiB
#include "tickets.h" #include <bits/stdc++.h> #define ll long long #define str string #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define vc vector<char> #define vvc vector<vc> #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vvvvi vector<vvvi> #define vll vector<ll> #define vvll vector<vll> #define vvvll vector<vvll> #define vvvvll vector<vvvll> #define vs vector<str> #define vvs vector<vs> #define vpii vector<pii> #define vvpii vector<vpii> #define vpll vector<pll> #define vvpll vector<vpll> #define vb vector<bool> #define vvb vector<vb> #define rep(i, a, b) for (int i = (a); i < int(b); i++) #define repi(i, a, b) for (int i = (a); i <= int(b); i++) using namespace std; int n, m; /*void allocate_tickets(vvi s) { rep(i, 0, n) { rep(j, 0, m) { cerr << s[i][j] << ' '; } cerr << '\n'; } }*/ ll find_maximum(int k, vvi tickets) { // yolo n = tickets.size(); m = tickets[0].size(); rep(i, 0, n) { sort(tickets[i].begin(), tickets[i].end()); } vi lo(n, 0); vi hi(n, m - 1); vvi assignment(n, vi(m, -1)); ll ans = 0; int round = 1; while (round <= k) { vll a(n); for (int i = 0; i < n; i += 2) { a[i] = tickets[i][lo[i]]; a[i + 1] = tickets[i + 1][hi[i]]; } vll b(n); for (int i = 0; i < n; i += 2) { b[i] = tickets[i][hi[i]]; b[i + 1] = tickets[i + 1][lo[i]]; } sort(a.begin(), a.end()); sort(b.begin(), b.end()); ll s1 = 0; ll s2 = 0; rep(i, 0, n) { s1 += abs(a[n / 2] - a[i]); s2 += abs(b[n / 2] - b[i]); } if (round == k) { if (s1 > s2) { for (int i = 0; i < n; i += 2) { assignment[i][lo[i]] = round - 1; assignment[i + 1][hi[i + 1]] = round - 1; } ans += s1; } else { for (int i = 0; i < n; i += 2) { assignment[i][hi[i]] = round - 1; assignment[i + 1][lo[i + 1]] = round - 1; } ans += s2; } } else { for (int i = 0; i < n; i += 2) { assignment[i][lo[i]] = round - 1; assignment[i + 1][hi[i + 1]] = round - 1; } for (int i = 0; i < n; i += 2) { assignment[i][hi[i]] = round; assignment[i + 1][lo[i + 1]] = round; } ans += s1 + s2; } rep(i, 0, n) { lo[i]++; hi[i]--; } round += 2; } allocate_tickets(assignment); return ans; } /* int main() { cout << find_maximum(2, {{0, 2, 5}, {1, 1, 3}}) << endl; cout << find_maximum(1, {{5, 9}, {1, 4}, {3, 6}, {2, 7}}) << endl; cout << find_maximum(2, {{3, 5}, {1, 3}, {3, 5}, {1, 3}}) << endl; cout << find_maximum(5, {{1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6}}) << endl; }*/
#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...