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 <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void Forgat(vector<vector<pair<int, int>>> &table, int ind, int k, int m, int f){
vector<pair<int, int>> temp(m);
for(int i = 0; i < m; i++)
{
if(i < m-k){
temp[i] = table[ind][i];
continue;
}
int x = ((i-m+k) + f)%k + m - k;
temp[x] = table[ind][i];
}
table[ind] = temp;
return;
}
long long find_maximum(int k, vector<vector<int>> table) {
int n = (int)table.size(), m = (int)table[0].size();
vector<pair<int, pair<int, int>>> sor;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
sor.push_back(make_pair(table[i][j], make_pair(i, j)));
vector<vector<pair<int, int>>> table2(n, vector<pair<int, int>>(m));
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
table2[i][j] = make_pair(1, j);
sort(sor.begin(), sor.end());
for(int i = 0; i < (int)sor.size()/2; i++)
table2[sor[i].second.first][sor[i].second.second].first = -1;
vector<pair<int, pair<int, pair<int, int>>>> csere;
int db = 0;
for(int i = 0; i < n; i++)
{
int x = 0;
for(int j = m-k; j < m; j++)
{
if(table2[i][j].first == -1)
db++;
if(table2[i][j].first == 1 && table2[i][x].first == -1)
{
csere.push_back(make_pair(table[i][j] + table[i][x], make_pair(i, make_pair(x, j))));
x++;
}
}
}
int x = 0;
while(db < n*k/2)
{
int a = csere[x].second.first, b = csere[x].second.second.first, c = csere[x].second.second.second;
swap(table2[a][b], table2[a][c]);
db++;
}
int forg = 0;
for(int i = 0; i < n; i++)
{
Forgat(table2, i, k, m, forg);
for(int j = m-k; j < m; j++)
if(table2[i][j].first == -1)
forg++;
forg %= k;
}
vector<vector<int>> answer(n, vector<int>(m));
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
if(j < m-k)
answer[i][table2[i][j].second] = -1;
else
answer[i][table2[i][j].second] = j-m+k;
}
}
long long ret = 0;
for(int i = 0; i < n; i++)
for(int j = m-k; j < m; j++)
ret += (long long)table2[i][j].first * table[i][table2[i][j].second];
allocate_tickets(answer);
return ret;
}
# | 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... |