이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#define ad push_back
#define lli long long
#define MP make_pair
#define sc second
#define fr first
using namespace std;
const int N = 2222;
int n, m;
vector<vector<int> > a;
int zr[N], l[N], r[N];
lli sum;
long long find_maximum(int k, std::vector<std::vector<int>> x)
{
n = x.size();
m = x[0].size();
a.resize(n);
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i].ad(-1);
priority_queue<pair<lli, int> > q, q1;
for (int i = 0; i < n; i++)
{
r[i] = m - 1;
if(i < n/2) zr[i] = k/2;
else zr[i] = (k+1)/2;
for (int j = 0; j < zr[i]; j++) sum -= x[i][j];
for (int j = m - 1; j >= m - k + zr[i]; j--) sum += x[i][j];
if(zr[i] != 0) q.push(MP(x[i][zr[i]-1]+x[i][m-k+zr[i]-1], i));
if(zr[i] != k) q1.push(MP(-x[i][zr[i]]-x[i][m-k+zr[i]], i));
}
while ((q.top().fr + q1.top().fr) > 0)
{
int i = q.top().sc, i1 = q1.top().sc;
if(zr[i] == 0 || ((x[i][zr[i]-1]+x[i][m-k+zr[i]-1]) != q.top().fr)) {q.pop(); continue;}
if(zr[i1] == k || ((-x[i1][zr[i1]]-x[i1][m-k+zr[i1]]) != q1.top().fr)) {q1.pop(); continue;}
sum += q.top().fr + q1.top().fr;
q.pop(); q1.pop();
zr[i]--; zr[i1]++;
if(zr[i] != 0) q.push(MP(x[i][zr[i]-1]+x[i][m-k+zr[i]-1], i));
if(zr[i] != k) q1.push(MP(-x[i][zr[i]]-x[i][m-k+zr[i]], i));
i = i1;
if(zr[i] != 0) q.push(MP(x[i][zr[i]-1]+x[i][m-k+zr[i]-1], i));
if(zr[i] != k) q1.push(MP(-x[i][zr[i]]-x[i][m-k+zr[i]], i));
}
for (int i = 0; i < k; i++)
{
vector<pair<int, int> > fp;
for (int j = 0; j < n; j++)
fp.ad(MP(zr[j], j));
sort(fp.begin(), fp.end());
reverse(fp.begin(), fp.end());
for (int j = 0; j < n / 2; j++)
a[fp[j].sc][l[fp[j].sc]++] = i, zr[fp[j].sc]--;
for (int j = n/2; j < n; j++)
a[fp[j].sc][r[fp[j].sc]--] = i;
}
allocate_tickets(a);
return sum;
}
# | 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... |