Submission #304628

#TimeUsernameProblemLanguageResultExecution timeMemory
304628loliconCarnival Tickets (IOI20_tickets)C++14
27 / 100
749 ms70772 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) void solve(int n, int k, vector<deque<pair<int, int>>> &T, vector<vector<int>> &ans) { int Cnt = 0; vector<int> cnt(n); vector<bool> type(n); vector<pair<int, int>> v; for(int i = 0; i < n; i++) { int l = T[i].front().first; int r = T[i].back().first; v.emplace_back(l, i); v.emplace_back(r, i); v.emplace_back((l + r) / 2, i); } sort(all(v)); for(int i = 0; i < 3 * n; i++) { cnt[v[i].second]++; if(cnt[v[i].second] == 2) { Cnt++; } if(Cnt == n / 2) { break; } } for(int i = 0; i < 3 * n; i++) { if(cnt[v[i].second] >= 2) // use L type[v[i].second] = false; else // use R type[v[i].second] = true; } for(int i = 0; i < n; i++) { if(type[i] == false) { ans[i][T[i].front().second] = k; T[i].pop_front(); } else { ans[i][T[i].back().second] = k; T[i].pop_back(); } } } long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> ans; for (int i = 0; i < n; i++) { vector<int> row(m, -1); ans.push_back(row); } vector<deque<pair<int, int>>> T(n); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { T[i].emplace_back(x[i][j], j); } } for(int i = 0; i < k; i++) { solve(n, i, T, ans); } // cal long long ret = 0; vector<vector<int>> TT(k); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(ans[i][j] != -1) { TT[ans[i][j]].push_back(x[i][j]); } } } for(int i = 0; i < k; i++) { sort(all(TT[i])); int p = TT[i][n / 2]; for(int j = 0; j < n; j++) { ret = ret + (long long)abs(p - TT[i][j]); } } allocate_tickets(ans); /*for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cout << ans[i][j] << " \n"[j == m - 1]; } }*/ return ret; }
#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...