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 "tickets.h"
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <iostream>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
using namespace std;
long long find_maximum(int k, vector<vector<int>> x)
{
int n = x.size();
int m = x[0].size();
vector<vector<int>> ret(n, vector<int>(m, -1));
long long ans = 0;
// int X[n], Y[n];
// for(int i = 0; i < n; ++i) X[i] = min_element(x[i].begin(), x[i].end()) - x[i].begin(), Y[i] = max_element(x[i].begin(), x[i].end()) - x[i].begin(), ans += x[i][Y[i]];
// vector<pii> tmp; for(int i = 0; i < n; ++i) tmp.push_back({x[i][X[i]] + x[i][Y[i]], i});
// sort(tmp.begin(), tmp.end());
// for(int i = 0; i < n / 2; ++i) ans -= tmp[i].ff, ret[tmp[i].ss][X[i]] = 0;
// for(int i = n / 2; i < n; ++i) ret[tmp[i].ss][Y[i]] = 0;
vector<int> lsX[n], lsY[n];
vector<pii> tmp;
for(int i = 0; i < n; ++i) for(int j = 0; j < k; ++j) ans += x[i][m - j - 1], tmp.push_back({x[i][j] + x[i][j + m - k], i});
sort(tmp.begin(), tmp.end());
// for(auto i : tmp) cout << i.ff << ' ' << i.ss << endl;
int cnt[n]{};
for(int i = 0; i < n * k / 2; ++i) ++cnt[tmp[i].ss], ans -= tmp[i].ff;
for(int i = 0; i < n; ++i)
{
for(int j = 0; j < cnt[i]; ++j) lsX[i].push_back(j);
for(int j = m - (k - cnt[i]); j < m; ++j) lsY[i].push_back(j);
}
for(int i = 0; i < k; ++i)
{
vector<pii> tmp2; for(int j = 0; j < n; ++j) tmp2.push_back({lsX[j].size(), j});
sort(tmp2.begin(), tmp2.end());
for(int j = 0; j < n / 2; ++j) ret[tmp2[j].ss][lsY[tmp2[j].ss].back()] = i, lsY[tmp2[j].ss].pop_back();
for(int j = n / 2; j < n; ++j) ret[tmp2[j].ss][lsX[tmp2[j].ss].back()] = i, lsX[tmp2[j].ss].pop_back();
}
allocate_tickets(ret);
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... |