This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
// void allocate_tickets(vector<vector<int>> answer){
// for(int i = 0; i<answer.size(); ++i) printArr(answer[i]);
// }
ll find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
ll ans = 0;
for(int i = 0; i<n; ++i)
for(int j = 0; j < k; ++j)
ans -= x[i][j];
vector<vector<int>> sigma(n);
for(int i = 0; i<n; ++i){
for(int j = 0; j < k; ++j){
sigma[i].push_back(x[i][j] + x[i][j + (m - k)]);
}
}
priority_queue<pair<int, int>> pq;
for(int i= 0; i<n; ++i) pq.push({sigma[i].back(), i});
for(int iteration = 0; iteration < n * k / 2; ++iteration){
pair<int, int> u = pq.top(); pq.pop();
ans += u.first;
sigma[u.second].pop_back();
if (sigma[u.second].size()){
pq.push({sigma[u.second].back(), u.second});
}
}
vector<vector<int>> answer(n, vector<int>(m, -1));
vector<vector<int>> nigga(n), possa(n);
for(int i = 0; i<n; ++i){
int l = sigma[i].size(), r = k - l;
for(int j = 0; j<l; ++j) nigga[i].push_back(j);
for(int j = 0; j<r; ++j) possa[i].push_back(m-j-1);
}
for(int run = 0; run < k; ++run){
vector<int> perm(n);
for(int i = 0; i<n; ++i) perm[i] = i;
sort(ALL(perm), [&nigga] (int x, int y){return nigga[x].size() > nigga[y].size();});
for(int i = 0; i<n/2; ++i){
int j = perm[i];
answer[j][nigga[j].back()] = run;
nigga[j].pop_back();
}
for(int i = n/2; i<n; ++i){
int j = perm[i];
answer[j][possa[j].back()] = run;
possa[j].pop_back();
}
}
allocate_tickets(answer);
return ans;
}
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int n, m, k; cin >> n >> m >> k;
// vector<vector<int>> a(n, vector<int>(m));
// for(int i = 0; i<n; ++i) {
// for(int j = 0 ;j<m; ++j) cin >> a[i][j];
// sort(ALL(a[i]));
// }
// cout << find_maximum(k, a) << "\n";
// return 0;
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |