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 <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>
using namespace std;
#define ll long long
#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
"%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif
#include "tickets.h"
int n, m, k;
int a[1505][1505];
int sign[1505][1505];
int nxt[1505];
vector<int> pos[1505], neg[1505];
int output_arr[1505][1505];
bool used[1505];
ll find_maximum(int K, vector<vector<int> > input)
{
n = input.size();
m = input[0].size();
k = K;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = input[i][j];
}
for (int j = 0; j < k; j++) {
sign[i][j] = -1;
}
nxt[i] = k - 1;
}
priority_queue<pair<ll, int> > pq;
for (int i = 0; i < n; i++) {
pq.push(make_pair((ll)a[i][k - 1] + (ll)a[i][m - 1], i));
}
for (int i = 1; i <= (n * k) / 2; i++) {
pair<ll, int> pr = pq.top(); pq.pop();
sign[pr.second][nxt[pr.second]]++;
sign[pr.second][nxt[pr.second] + m - k]++;
if (nxt[pr.second]) {
nxt[pr.second]--;
pr.first = (ll)a[pr.second][nxt[pr.second]] +
(ll)a[pr.second][nxt[pr.second] + m - k];
pq.push(pr);
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ans += (ll)a[i][j] * (ll)sign[i][j];
if (sign[i][j] > 0) {
pos[i].push_back(j);
} else if (sign[i][j] < 0) {
neg[i].push_back(j);
}
}
}
for (int i = 1; i <= k; i++) {
int pos_chosen = 0, neg_chosen = 0;
for (int j = 0; j < n; j++) used[j] = false;
for (int j = 0; j < n; j++) {
if (pos[j].empty()) {
neg_chosen++; output_arr[j][neg[j].back()] = i;
neg[j].pop_back(); used[j] = true;
} else if (neg[j].empty()) {
pos_chosen++; output_arr[j][pos[j].back()] = i;
pos[j].pop_back(); used[j] = true;
}
}
for (int j = 0; j < n; j++) {
if (used[j]) continue;
if (pos_chosen < n / 2) {
pos_chosen++; output_arr[j][pos[j].back()] = i;
pos[j].pop_back();
} else {
neg_chosen++; output_arr[j][neg[j].back()] = i;
neg[j].pop_back();
}
}
}
vector<vector<int> > final_ans(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
final_ans[i].push_back(output_arr[i][j] - 1);
}
}
allocate_tickets(final_ans);
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... |