이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
long long find_maximum(int K, std::vector<std::vector<int>> x)
{
int N = x.size();
int M = x[0].size();
ll value = 0;
vvi ans(N, vi(M, -1));
vvi mapping(N, vi(M, -1)); // mapping of pairs
vvi useNega(N, vi(M, 0));
vpii gains;
for (int i = 0; i < N; ++i)
{
vpii A(M);
for (int j = 0; j < M; ++j)
A[j] = {x[i][j], i * M + j};
sort(all(A));
int delta = M - K;
for (int j = 0; j < K; ++j)
{
value -= A[j].first;
useNega[i][A[j].second % M] = 1; // i use it as a negative
mapping[i][A[j + delta].second % M] = A[j].second % M;
gains.push_back({A[j].first + A[j + delta].first, A[j + delta].second});
}
}
sort(all(gains));
reverse(all(gains));
gains.resize(K * N / 2);
sort(all(gains), [&](const pii &a, const pii &b)
{ return a.second / M < b.second / M; });
vvi RoundUsed(N, vi(K, 0));
for (int l = 0, i, j; l < K * N / 2; ++l)
{
pii tmp = gains[l];
i = tmp.second / M, j = tmp.second % M;
value += tmp.first;
useNega[i][mapping[i][j]] = 0;
ans[i][j] = l % K;
RoundUsed[i][l % K] = 1;
}
for (int i = 0; i < N; ++i)
{
int k = 0;
for (int j = 0; j < M; ++j)
if (useNega[i][j])
{
while (RoundUsed[i][k])
++k;
ans[i][j] = k++;
}
}
allocate_tickets(ans);
return value;
}
# | 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... |