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 "tickets.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll find_maximum(int k, vector<vector<int>> x) {
int n = (int)x.size();
int m = (int)x[0].size();
ll ans = 0;
vector<vector<int>> znak(n, vector<int>(m, 0));
priority_queue<pair<ll, pair<int, int>>> pq;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < k; ++j) {
ans -= x[i][j];
znak[i][j] = -1;
int ind = k-1-j;
ind = m-1-ind;
ll dodaj = x[i][j] + x[i][ind];
pq.push({dodaj, {i, j}});
}
}
for(int uradi = 0; uradi < n*k/2; ++uradi) {
auto tren = pq.top();
ans += tren.first;
pair<int, int> mesto = tren.second;
pq.pop();
znak[mesto.first][mesto.second] = 0;
int ind = k-1-mesto.second;
ind = m-1-ind;
znak[mesto.first][ind] = 1;
}
vector<stack<int>> minus(n), plus(n);
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
if(znak[i][j] == -1) {
minus[i].push(j);
} else if(znak[i][j] == 1) {
plus[i].push(j);
}
}
}
//for(int i = 0; i < n; ++i) {
//for(int j = 0; j < m; ++j) {
//cerr << znak[i][j] << " ";
//}
//cerr << endl;
//}
vector<vector<int>> odg(n, vector<int>(m, -1));
for(int uradi = 0; uradi < k; ++uradi) {
vector<bool> marked(n, false);
vector<bool> plusici, minusici;
plusici = marked;
minusici = marked;
for(int i = 0; i < n; ++i) {
if(!minus[i].empty()) {
minusici[i] = true;
}
if(!plus[i].empty()) {
plusici[i] = true;
}
}
vector<int> moraPlus, moraMinus;
for(int i = 0; i < n; ++i) {
if(plusici[i] && !minusici[i]) {
moraPlus.push_back(i);
}
if(minusici[i] && !plusici[i]) {
if((int)moraMinus.size() < n/2) {
marked[i] = true;
}
moraMinus.push_back(i);
}
}
for(int i = 0; i < n && (int)moraMinus.size() < n/2; ++i) {
if(marked[i])
continue;
if(!minus[i].empty()) {
marked[i] = true;
moraMinus.push_back(i);
}
}
for(int i = 0; i < n; ++i) {
if(marked[i]) {
odg[i][minus[i].top()] = uradi;
minus[i].pop();
} else {
odg[i][plus[i].top()] = uradi;
plus[i].pop();
}
}
}
allocate_tickets(odg);
return ans;
}
# | 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... |