이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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){
int c0 = 0;
int c1 = 0;
for (int j = 0; j < m; ++j){
c0+=1-d[i][j];
c1+=d[i][j];
}
c0 = min(c0,k);
c1 = min(c1,k);
cnt0+=c0-c1;
}
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... |