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 <bits/stdc++.h>
#include "tickets.h"
using namespace std;
struct el {
long long x, y, idx;
bool operator < (const el &oth) const {
return (x - y) < (oth.x - oth.y);
}
};
bool comp (pair <long, long> a, pair <long, long> b) {
return (a.first - b.second) > (b.first - b.second);
}
long long find_maximum(int k, vector<vector<int>> x) {
long long n = x.size();
long long m = x[0].size();
if (m == 1){ // subtask 1
vector<vector<int>> answer (n, vector <int> (m));
long long rs = 0;
vector <int> v;
for (int i = 0; i < n; i++){
v.push_back(x[i][0]);
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++){
rs+=abs(x[i][0] - v[n / 2]);
}
allocate_tickets(answer);
return rs;
}
else if (k == 1) { // subtask 2
vector<vector<int>> answer (n, vector <int> (m, -1));
vector <int> is (n);
long long rs = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
vector <int> tis (n);
tis[i] = j;
long long trs = 0;
int low = 0, high = 0;
vector <el > v;
for (int k = 0; k < n; k++){
if (i == k) continue;
if (x[k][m-1] < x[i][j]) {
tis[k] = 0;
low++;
trs+=x[i][j] - x[k][0];
}
else if (x[k][0] > x[i][j]) {
tis[k] = m - 1;
high++;
trs+=x[k][m-1] - x[i][j];
}
else {
v.push_back({x[i][j] - x[k][0], x[k][m-1] - x[i][j], k});
}
}
if (low >= n / 2 || high > n / 2) continue;
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for (auto now: v) {
if (low != n / 2) {
trs+=now.x;
tis[now.idx] = 0;
}
else {
trs+=now.y;
tis[now.idx] = m - 1;
}
}
if (trs > rs) {
rs = trs;
is = tis;
}
}
}
for (int i = 0; i < n; i++){
answer[i][is[i]] = 0;
}
allocate_tickets(answer);
return rs;
}
else { // subtask 3
// int n0 = 0, n1 = 0;
// for (int i = 0; i < n; i++){
// for (int j = 0; j < m; j++){
// n0+=x[i][j] == 0;
// n1+=x[i][j] == 1;
// }
// }
// for (int i = 0; i < k; i++){
// }
}
return -1;
}
# | 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... |