이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "tickets.h"
#define mp make_pair
using namespace std;
typedef long long ll;
struct Add_Positive {
int colour;
int rm;
int add;
};
int N, M, K;
vector<vector<int>> x;
vector<vector<int>> s;
priority_queue<Add_Positive> q;
vector<set<int>> pl;
vector<set<int>> mi;
bool plus_sort(const int& a, const int& b)
{
return pl[a].size() < pl[b].size();
}
bool operator < (const Add_Positive&a, const Add_Positive& b) {
return x[a.colour][a.rm] + x[a.colour][a.add] < x[b.colour][b.add] + x[b.colour][b.rm];
}
ll find_maximum(int k, vector<vector<int>> X)
{
N = X.size();
M = X[0].size();
x = X;
K = k;
s.assign(N, vector<int>(M, -1));
pl.resize(N);
mi.resize(N);
int begin_pos = M - K;
ll ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < K; j++) {
ans -= x[i][j];
mi[i].insert(j);
q.push({i, j, j + begin_pos});
}
}
for (int cnt = 0; cnt < K * N / 2; cnt++) {
// Swap a negative for a positive
auto cur = q.top();
q.pop();
ans += x[cur.colour][cur.add] + x[cur.colour][cur.rm];
mi[cur.colour].erase(cur.rm);
pl[cur.colour].insert(cur.add);
}
for (int r = 0; r < K; r++) {
vector<int> p;
for (int i = 0; i < N; i++)
p.push_back(i);
sort(p.begin(), p.end(), plus_sort);
for (int i = 0; i < N / 2; i++) {
int v = p[i];
s[v][*mi[v].begin()] = r;
mi[v].erase(mi[v].begin());
}
for (int i = N / 2; i < N; i++) {
int v = p[i];
s[v][*pl[v].begin()] = r;
pl[v].erase(pl[v].begin());
}
}
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... |