# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
592465 | ogibogi2004 | Carnival Tickets (IOI20_tickets) | C++14 | 1 ms | 212 KiB |
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<bits/stdc++.h>
using namespace std;
#define ll long long
long long find_maximum(int k, vector<vector<int>> x1) {
//cout<<"?\n";
vector<vector<ll> >x;
for(int i=0;i<x1.size();i++)
{
vector<ll>row;
for(int j=0;j<x1[i].size();j++)row.push_back(x1[i][j]);
x.push_back(row);
}
ll n = x.size();
ll m = x[0].size();
vector<vector<int>> answer;
vector<pair<ll,ll>>smallest[n];
int ptr1[n],ptr2[n];
for(ll i=0;i<n;i++)
{
for(ll j=0;j<m;j++)smallest[i].push_back({x[i][j],j});
sort(smallest[i].begin(),smallest[i].end());
ptr1[i]=0;ptr2[i]=smallest[i].size()-1;
}
answer=x1;
for(int i=0;i<answer.size();i++)
{
for(int j=0;j<answer[i].size();j++)
{
answer[i][j]=-1;
}
}
int min0=0,max0=0;
for(int i=0;i<n;i++)
{
int cnt0=0,cnt1=0;
for(int j=0;j<m;j++)
{
if(x[i][j]==0)cnt0++;
else cnt1++;
}
max0+=min(k,cnt0);
min0+=max(0,k-cnt1);
}
int target;
if(n*k/2>=min0&&n*k/2<=max0)target=n*k/2;
else if(n*k/2<min0)target=min0;
else target=max0;
vector<int>zero[n],one[n];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(x[i][j]==0)zero[i].push_back(j);
else one[i].push_back(j);
}
}
for(int r=0;r<k;r++)
{
int f=min(target,max(k/2,target-(k-r-1)*k));
target-=f;
vector<pair<int,int> >v;
for(int i=0;i<n;i++)
{
v.push_back({zero[i].size(),i});
}
sort(v.rbegin(),v.rend());
for(int j=0;j<v.size();j++)
{
if(j<f)
{
answer[v[j].second][zero[v[j].second].back()]=r;
zero[v[j].second].pop_back();
}
else
{
answer[v[j].second][one[v[j].second].back()]=r;
one[v[j].second].pop_back();
}
}
}
allocate_tickets(answer);
return min((int)target,(int)n*k-target);
}
/*
2 3 2
0 2 5
1 1 3
*/
/*
4 4 3
0 1 1 1
0 1 1 1
0 1 1 1
0 0 0 1
*/
Compilation message (stderr)
# | 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... |