Submission #301223

#TimeUsernameProblemLanguageResultExecution timeMemory
301223IgorICarnival Tickets (IOI20_tickets)C++17
100 / 100
1434 ms109712 KiB
#include <bits/stdc++.h> #include "tickets.h" using namespace std; void allocate_tickets(vector<vector<int> > ans) ; vector<vector<int> > solve01(int k, vector<vector<int> > x) { int n = x.size(), m = x[0].size(); long long res = 0; vector<vector<int> > ans(n, vector<int>(m, -1)); vector<pair<int, int> > z; vector<int> fr(n), to(n, m - 1); for (int i = 0; i < n; i++) { int cnt = 0; for (int j = 0; j < m; j++) { cnt += (x[i][j] == 0); } z.push_back({cnt, i}); } for (int j = 0; j < k; j++) { sort(z.begin(), z.end()); reverse(z.begin(), z.end()); int cnt0 = 0, cnt1 = 0; for (int i = 0; i < n / 2; i++) { if (z[i].first > 0) { z[i].first--; ans[z[i].second][fr[z[i].second]] = j; fr[z[i].second]++; cnt0++; } else { ans[z[i].second][to[z[i].second]] = j; to[z[i].second]--; cnt1++; } } for (int i = n / 2; i < n; i++) { if (z[i].first < m - j) { ans[z[i].second][to[z[i].second]] = j; to[z[i].second]--; cnt1++; } else { z[i].first--; ans[z[i].second][fr[z[i].second]] = j; fr[z[i].second]++; cnt0++; } } res += min(cnt0, cnt1); } return ans; } long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(), m = x[0].size(); vector<vector<int> > edit(n, vector<int>(m, -1)); vector<pair<long long, pair<int, int> > > moo; long long res = 0; for (int e = 0; e < k; e++) { for (int i = 0; i < n; i++) { edit[i][e] = 0; res -= x[i][e]; moo.push_back({x[i][e] + x[i][e + m - k], {i, e}}); } } sort(moo.begin(), moo.end()); reverse(moo.begin(), moo.end()); for (int i = 0; i < n / 2 * k; i++) { res += moo[i].first; int a = moo[i].second.first; int b = moo[i].second.second; edit[a][b] = -1; edit[a][b + m - k] = 1; } vector<vector<int> > x2(n); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (edit[i][j] != -1) x2[i].push_back(edit[i][j]); } } vector<vector<int> > ans2 = solve01(k, x2); vector<vector<int> > ans(n, vector<int>(m, -1)); for (int i = 0; i < n; i++) { int p = 0; for (int j = 0; j < m; j++) { if (edit[i][j] != -1) { ans[i][j] = ans2[i][p]; p++; } } } allocate_tickets(ans); return res; }
#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...