이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;
typedef long long ll;
const int maxn = 1510;
int a[maxn];
int turno[maxn][maxn];
int ord[maxn], 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 (m == 1)
{
vector<vector<int>> S;
for (int i = 0; i < n; i++)
{
vector<int> y;
y.resize(m);
y[0] = 0;
S.push_back(y);
}
allocate_tickets(S);
for (int i = 0; i < n; i++)
a[i] = x[i][0];
sort(a, a+n);
int med = a[n/2];
ll ans = 0;
for (int i = 0; i <= n/2; i++)
ans += 1ll*(med-a[i]);
for (int i = n/2 + 1; i < n; i++)
ans += 1ll*(a[i]-med);
return ans;
}
for (int i = 0; i < n; i++)
{
memset(turno[i], -1, sizeof turno[i]);
ord[i] = 0, 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 = 1; 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 + 1; 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... |