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 <vector>
#include <bits/stdc++.h>
using namespace std;
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
bool vien = true;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (x[i][j] < 0 || x[i][j] > 1)
vien = false;
vector<vector<int>> answer(n, vector<int>(m, -1));
int mxp = n / 2 * k;
int M[n], P[n];
if (vien)
{
for (int i = 0; i < n; i++)
{
P[i] = 0;
while (P[i] < m && x[i][m - 1 - P[i]] == 1)
P[i]++;
}
for (int i = 0; i < n; i++)
M[i] = k - P[i];
}
else if (k < m)
{
long long del[n][k + 1];
for (int i = 0; i < n; i++)
{
long long d = 0;
for (int c = 0; c < k; c++)
d -= x[i][c];
for (int p = 0; p <= k; p++)
{
del[i][p] = d;
d += x[i][k - 1 - p];
d += x[i][m - 1 - p];
}
}
vector<pair<int, int>>A;
for (int i = 0; i < n; i++)
{
M[i] = P[i] = 0;
for (int j = 0; j < k; j++)
A.push_back({del[i][j + 1] - del[i][j], i});
}
sort(A.begin(), A.end());
for (int i = 0; i < (int)A.size() / 2; i++)
{
M[A[i].second]++;
}
for (int i = (int)A.size() / 2; i < (int)A.size(); i++)
{
P[A[i].second]++;
}
}
else
{
vector<pair<int, int>>A;
for (int i = 0; i < n; i++)
{
M[i] = P[i] = 0;
for (int j = 0; j < m; j++)
A.push_back({x[i][j], i});
}
sort(A.begin(), A.end());
for (int i = 0; i < (int)A.size() / 2; i++)
{
M[A[i].second]++;
}
for (int i = (int)A.size() / 2; i < (int)A.size(); i++)
{
P[A[i].second]++;
}
}
int a[n];
int b[n];
for (int i = 0; i < n; i++)
{
a[i] = 0;
b[i] = m - 1;
}
long long ret = 0;
for (int g = 0; g < k; g++)
{
pair<int, int>xx[n];
for (int i = 0; i < n; i++)
xx[i] = {P[i], i};
sort(xx, xx + n);
for (int i = 0; i < n / 2; i++)
{
int id = xx[i].second;
ret -= x[id][a[id]];
answer[id][a[id]] = g;
a[id]++;
M[id]--;
}
for (int i = n / 2; i < n; i++)
{
int id = xx[i].second;
ret += x[id][b[id]];
answer[id][b[id]] = g;
b[id]--;
P[id]--;
}
}
allocate_tickets(answer);
return ret;
}
Compilation message (stderr)
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:14:6: warning: unused variable 'mxp' [-Wunused-variable]
14 | int mxp = n / 2 * k;
| ^~~
# | 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... |