이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <cassert>
#include <cstdio>
#include <vector>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int fr[1505];
deque <pair <int,int> > ceaules[1505];
vector <vector <int> > matrfin;
long long find_maximum(int k, std::vector<std::vector<int>> x)
{
int i,j;
int n = x.size();
int m = x[0].size();
for (i=0; i<n; i++)
{
for (j=0; j<m; j++)
{
ceaules[i].push_back({x[i][j],j});
}
}
matrfin.resize(n);
for (i=0;i<n;i++)
{
matrfin[i].resize(m);
}
long long solfin=0;
for (i=1; i<=k; i++)
{
vector <pair <int,pair <int,int> >> bonjour;
for (j=0; j<n; j++)
{
fr[j]=0;
bonjour.push_back({ceaules[j].front().first,{ceaules[j].front().second,j}});
bonjour.push_back({ceaules[j].back().first,{ceaules[j].back().second,j}});
}
sort (bonjour.begin(),bonjour.end());
int cateiau=n/2;
long long sum=0;
for (j=0; j<2*n; j++)
{
int loc=bonjour[j].second.second;
if (fr[loc]==0)
{
fr[loc]=1;
matrfin[loc][bonjour[j].second.first]=i;
if (bonjour[j].first==ceaules[loc].front().first)
{
ceaules[loc].pop_front();
}
else
{
ceaules[loc].pop_back();
}
sum=sum-bonjour[j].first;
cateiau--;
if (cateiau==0)
{
break;
}
}
}
for (j=2*n-1; j>=0; j--)
{
if (fr[bonjour[j].second.second]==1)
{
continue;
}
fr[bonjour[j].second.second]=1;
int loc=bonjour[j].second.second;
matrfin[loc][bonjour[j].second.first]=i;
if (bonjour[j].first==ceaules[loc].front().first)
{
ceaules[loc].pop_front();
}
else
{
ceaules[loc].pop_back();
}
sum=sum+bonjour[j].first;
cateiau--;
if (cateiau==0)
{
break;
}
}
cateiau=n/2;
solfin=solfin+sum;
}
for (i=0;i<n;i++)
{
for (j=0;j<m;j++)
{
matrfin[i][j]--;
}
}
allocate_tickets(matrfin);
return solfin;
}
#ifdef HOME
static int n;
static int m;
static int k;
static std::vector<std::vector<int>> d;
static std::vector<std::vector<int>> x;
static int called = 0;
static void check(bool cond, std::string message)
{
if (!cond)
{
printf("%s\n", message.c_str());
exit(0);
}
}
void allocate_tickets( std::vector<std::vector<int>> _d)
{
check(!called, "allocate_tickets called more than once");
d = _d;
check((int)d.size() == n, "allocate_tickets called with parameter of wrong size");
for (int i = 0; i < n; i++)
{
check((int)d[i].size() == m, "allocate_tickets called with parameter of wrong size");
}
called = 1;
}
int main()
{
assert(scanf("%d %d %d", &n, &m, &k) == 3);
x.resize(n);
for (int i = 0; i < n; i++)
{
x[i].resize(m);
for (int j=0; j < m; j++)
{
assert(scanf("%d", &x[i][j]) == 1);
}
}
fclose(stdin);
long long answer = find_maximum(k, x);
check(called, "failure to call allocate_tickets");
printf("%lld\n", answer);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (j) printf(" ");
printf("%d", d[i][j]);
}
printf("\n");
}
fclose(stdout);
return 0;
}
#endif // HOME
# | 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... |