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;
struct el {
long long x, y, idx;
bool operator < (const el &oth) const {
return y + x < oth.x + oth.y;
}
};
struct val {
long long v, x, y;
bool operator < (const val &oth) const {
return v < oth.v;
}
};
// bool comp (pair <long, long> a, pair <long, long> b) {
// if (a.first != b.first) return a.first <
// }
long long find_maximum(int k, vector<vector<int>> x) {
long long n = x.size();
long long m = x[0].size();
long long rs = 0;
vector <int> times (n, 1);
vector <vector <int> > answer (n, vector <int> (m, -1));
vector <vector <bool> > take (n, vector <bool> (m, 0));
priority_queue <el> pq;
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++){
rs-=x[i][j];
take[i][j] = 1;
}
pq.push({x[i][k-1], x[i][m-1], i});
}
for (int z = 0; z < n * k / 2; z++){
el now = pq.top();
pq.pop();
rs+=now.x + now.y;
take[now.idx][k - times[now.idx]] = 0;
take[now.idx][m - times[now.idx]] = 1;
if (times[now.idx] != k) {
times[now.idx]++;
now.x = x[now.idx][k - times[now.idx]];
now.y = x[now.idx][m - times[now.idx]];
pq.push(now);
}
}
vector <val> v;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (take[i][j]) {
v.push_back({x[i][j], i, j});
}
}
}
sort(v.begin(), v.end());
for (int z = 0; z < k; z++){
vector <int> row (n, 0);
int low = 0, high = 0;
for (int i = 0; i < n * k && low != n / 2; i++){
if (!row[v[i].x] && answer[v[i].x][v[i].y] == -1) {
low++;
row[v[i].x] = 1;
answer[v[i].x][v[i].y] = z;
}
}
for (int i = n * k - 1; i >= 0 && high != n / 2; i--){
if (!row[v[i].x] && answer[v[i].x][v[i].y] == -1) {
row[v[i].x] = 1;
answer[v[i].x][v[i].y] = z;
high++;
}
}
}
allocate_tickets(answer);
return rs;
}
# | 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... |