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;
long long find_maximum(int k, std::vector<std::vector<int>> x)
{
int mx = 0;
int n = x.size(), m = x[0].size();
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
mx = max(mx, x[i][j]);
}
}
if (mx == 1)
{
long long res;
vector<vector<int> > ans(n, vector<int>(m, -1));
vector<pair<int, int> > z;
vector<int> fr(n), to(n, m - 1);
for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = 0; j < m; j++)
{
cnt += (x[i][j] == 0);
}
z.push_back({cnt, i});
}
for (int j = 0; j < k; j++)
{
sort(z.begin(), z.end());
reverse(z.begin(), z.end());
int cnt0 = 0, cnt1 = 0;
for (int i = 0; i < n / 2; i++)
{
if (z[i].first > 0)
{
z[i].first--;
ans[z[i].second][fr[z[i].second]] = j;
fr[z[i].second]++;
cnt0++;
}
else
{
ans[z[i].second][to[z[i].second]] = j;
to[z[i].second]--;
cnt1++;
}
}
for (int i = n / 2; i < n; i++)
{
if (z[i].first < m - j)
{
ans[z[i].second][to[z[i].second]] = j;
to[z[i].second]--;
cnt1++;
}
else
{
z[i].first--;
ans[z[i].second][fr[z[i].second]] = j;
fr[z[i].second]++;
cnt0++;
}
}
res += min(cnt0, cnt1);
}
allocate_tickets(ans);
return res;
}
vector<pair<long long, int> > improve;
vector<vector<int> > ans(n, vector<int>(m, -1));
long long si = 0;
for (int i = 0; i < n; i++)
{
si -= x[i][0];
improve.push_back({x[i][0] + x[i][m - 1], i});
}
sort(improve.begin(), improve.end());
reverse(improve.begin(), improve.end());
for (int i = 0; i < n / 2; i++)
{
ans[improve[i].second][m - 1] = 0;
si += improve[i].first;
}
for (int i = n / 2; i < n; i++)
{
ans[improve[i].second][0] = 0;
}
allocate_tickets(ans);
return si;
}
Compilation message (stderr)
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:19:19: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
19 | long long res;
| ^~~
# | 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... |