제출 #792156

#제출 시각아이디문제언어결과실행 시간메모리
792156mousebeaver카니발 티켓 (IOI20_tickets)C++14
11 / 100
1 ms596 KiB
#define ll long long #define pll pair<ll, ll> #include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector<vector<int>> x) { ll n = x.size(); ll m = x[0].size(); if(m == 1) { vector<vector<int>> output(n, vector<int> (1, 0)); allocate_tickets(output); vector<ll> a(n); for(ll i = 0; i < n; i++) { a[i] = x[i][0]; } sort(a.begin(), a.end()); ll ans = 0; ll add = 0; for(ll i = n/2; i >= 0; i--) { add = a[n/2] - a[i]; ans += add; } for(ll i = n/2+1; i < n; i++) { add = a[i] - a[n/2]; ans += add; } return ans; } if(k == 1) { ll ans = -1; vector<vector<int>> output(n, vector<int> (m, -1)); for(ll i = 0; i < n; i++) { ll median = x[i][m-1]; ll sum = 0; ll below = 0; //Counter for the ones that can not go high enough vector<pll> downfall(0); //What is won by going down vector<ll> bottom(0); for(ll j = 0; j < n; j++) { if(i != j) { if(x[j][m-1] >= median) { //May go above sum += x[j][m-1] - median; if(x[j][0] <= 0) { downfall.push_back({(median-x[j][0]) - (x[j][m-1]-median), j}); } } else { //Has to go below below++; bottom.push_back(j); sum += median - x[j][0]; } } } if(below <= n/2 && below+(int) downfall.size() >= n/2) { //Being median is possible sort(downfall.begin(), downfall.end()); reverse(downfall.begin(), downfall.end()); for(ll j = below+1; j <= n/2; j++) { sum += downfall[j].first; bottom.push_back(downfall[j].second); } if(sum > ans) { ans = sum; for(int j = 0; j < n; j++) { output[j][0] = -1; output[j][m-1] = 0; } for(int j : bottom) { output[j][0] = 0; output[j][m-1] = -1; } } } } allocate_tickets(output); return ans; } vector<ll> zcount(n, 0); for(ll i = 0; i < n; i++) { for(ll j = 0; j < m; j++) { zcount[i] += (x[i][j] == 0); } } vector<ll> zind(n, 0); vector<ll> oind(n, 0); //Index of first zero/one vector<vector<int>> output(n, vector<int> (m, -1)); ll ans = 0; for(ll i = 0; i < k; i++) { vector<pll> zsort(n); for(ll j = 0; j < n; j++) { zsort[j] = {zcount[j], j}; } sort(zsort.begin(), zsort.end()); vector<bool> big(n, true); for(ll j = n/2; j < n; j++) { big[zsort[j].second] = false; } ll counter = 0; for(ll j = 0; j < n; j++) { if((big[j] && zcount[j] < m-i) || (!big[j] && zcount[j] == 0)) { //Give a one while(x[j][oind[j]] != 1) { oind[j]++; } output[j][oind[j]] = i; oind[j]++; counter++; } else { //Give a zero while(x[j][zind[j]] != 0) { zind[j]++; } output[j][zind[j]] = i; zind[j]++; zcount[j]--; } } ans += min(counter, n-counter); } allocate_tickets(output); return ans; }
#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...