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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool is_max[1501][1501];
set<int> a[1501];
int cnt[1501];
long long find_maximum(int k, vector<vector<int>> d) {
int n = d.size();
int m = d[0].size();
int cnt0 = 0;
for (int i = 0; i < n; ++i){
for (int j = 0; j < m; ++j){
cnt0+=1-2*d[i][j];
}
}
if(cnt0 > 0){
vector<vector<int>> ans(d.size(),vector<int>(d[0].size(),-1));
ll sum = 0;
vector<pair<int,pair<int,int>>> vals;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
vals.push_back({d[i][j],{i,j}});
a[i].insert(j);
}
}
sort(vals.begin(),vals.end());
reverse(vals.begin(),vals.end());
int last_max = 0;
int J = 0;
for (int i = 0; i < n*k/2+J; ++i)
{
if(cnt[vals[i].second.first] == k){
J++;
continue;
}
cnt[vals[i].second.first]++;
//cout << "TAKE " << vals[i].second.first << " " << vals[i].second.second << "\n";
is_max[vals[i].second.first][vals[i].second.second] = 1;
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
if(is_max[i][j]){
sum+=d[i][j];
a[i].erase(last_max);
ans[i][j] = last_max++;
last_max%=k;
}
}
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j+cnt[i] < k; ++j)
{
sum-=d[i][j];
ans[i][j] = *a[i].begin();
a[i].erase(a[i].begin());
}
}
allocate_tickets(ans);
return sum;
}
vector<vector<int>> ans(d.size(),vector<int>(d[0].size(),-1));
ll sum = 0;
vector<pair<int,pair<int,int>>> vals;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
vals.push_back({d[i][j],{i,j}});
a[i].insert(j);
}
}
sort(vals.begin(),vals.end());
int last_max = 0;
int J = 0;
for (int i = 0; i < n*k/2+J; ++i)
{
if(cnt[vals[i].second.first] == k){
J++;
continue;
}
cnt[vals[i].second.first]++;
is_max[vals[i].second.first][vals[i].second.second] = 1;
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
if(is_max[i][j]){
sum+=d[i][j];
a[i].erase(last_max);
ans[i][j] = last_max++;
last_max%=k;
}
}
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j+cnt[i] < k; ++j)
{
sum-=d[i][m-1-j];
ans[i][m-1-j] = *a[i].begin();
a[i].erase(a[i].begin());
}
}
allocate_tickets(ans);
return -sum;
}
# | 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... |