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;
const int maxn = 1510;
int turno[maxn][maxn];
int ord[maxn];
int qtd[maxn];
int ptr_l[maxn], ptr_r[maxn];
ll find_maximum(int k, vector<vector<int>> x)
{
int n = x.size();
int m = x[0].size();
if (k == 1)
{
for (int i = 0; i < n; i++)
{
memset(turno[i], -1, sizeof turno[i]);
ord[i] = i;
}
sort(ord, ord+n, [&] (int a, int b) {return x[a][0]+x[a][m-1] > x[b][0]+x[b][m-1];});
ll ans = 0;
for (int i = 0; i < n/2; i++)
{
turno[ord[i]][m-1] = 0;
ans += 1ll*x[ord[i]][m-1];
}
for (int i = n/2; i < n; i++)
{
turno[ord[i]][0] = 0;
ans -= 1ll*x[ord[i]][0];
}
vector<vector<int>> S;
for (int i = 0; i < n; i++)
{
vector<int> y;
y.resize(m);
for (int j = 0; j < m; j++)
y[j] = turno[i][j];
S.push_back(y);
}
allocate_tickets(S);
return ans;
}
for (int i = 0; i < n; i++)
{
memset(turno[i], -1, sizeof turno[i]);
ord[i] = i, ptr_l[i] = 0, ptr_r[i] = m-1;
for (int j = 0; j < m; j++)
if (x[i][j] == 0)
qtd[i]++;
}
ll ans = 0;
for (int r = 0; r < k; r++)
{
sort(ord, ord+n, [&] (int a, int b) {return qtd[a] > qtd[b];});
int tot[2];
tot[0] = 0, tot[1] = 0;
for (int i = 0; i < n/2; i++)
{
int j = ord[i];
turno[j][ptr_l[j]] = r;
tot[x[j][ptr_l[j]]]++;
if (x[j][ptr_l[j]] == 0) qtd[j]--;
ptr_l[j]++;
}
for (int i = n/2; i < n; i++)
{
int j = ord[i];
turno[j][ptr_r[j]] = r;
tot[x[j][ptr_r[j]]]++;
if (x[j][ptr_r[j]] == 0) qtd[j]--;
ptr_r[j]--;
}
ans += 1ll*min(tot[0], tot[1]);
}
vector<vector<int>> S;
for (int i = 0; i < n; i++)
{
vector<int> y;
y.resize(m);
for (int j = 0; j < m; j++)
y[j] = turno[i][j];
S.push_back(y);
}
allocate_tickets(S);
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... |