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"
#define ff first
#define ss second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 1510;
int turno[maxn][maxn];
int ord[maxn];
int qtd[maxn], 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 == m)
{
ll ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ans -= 1ll*x[i][j];
priority_queue<pair<int, pii>> fila;
for (int i = 0; i < n; i++)
{
memset(turno[i], -1, sizeof turno[i]);
fila.push({2*x[i][m-1], {i, m-1}});
qtd[i] = 0, ord[i] = i;
ptr_l[i] = 0, ptr_r[i] = m-1;
}
for (int t = 0; t < (n*m)/2; t++)
{
auto pp = fila.top(); fila.pop();
ans += 1ll*pp.ff;
if (qtd[pp.ss.ff] == m) continue;
qtd[pp.ss.ff]++;
fila.push({2*x[pp.ss.ff][pp.ss.ss-1], {pp.ss.ff, pp.ss.ss-1}});
}
for (int r = 0; r < k; r++)
{
sort(ord, ord+n, [&] (int a, int b) {return qtd[a] > qtd[b];});
for (int i = 0; i < n/2; i++)
{
int j = ord[i];
turno[j][ptr_r[j]] = r;
ptr_r[j]--;
qtd[j]--;
}
for (int i = n/2; i < n; i++)
{
int j = ord[i];
turno[j][ptr_l[j]] = r;
ptr_l[j]++;
}
}
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;
}
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... |