이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1500;
int N, M, K;
int A[MAXN+10][MAXN+10];
int P[MAXN+10];
int ans2[MAXN+10][MAXN+10];
ll ans;
int L[MAXN+10], R[MAXN+10], chk[MAXN+10];
ll find_maximum(int _K, vector<vector<int>> _X)
{
N=_X.size(); M=_X[0].size(); K=_K;
for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) A[i][j]=_X[i-1][j-1];
for(int i=1; i<=N; i++) P[i]=0;
vector<pii> V;
for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) V.push_back({A[i][j], i});
sort(V.begin(), V.end());
for(int i=0; i<N*M/2; i++)
{
int now=V[i].second;
P[now]++;
}
int cnt=0;
for(int i=1; i<=N; i++) if(P[i]==0) cnt++;
priority_queue<pii> PQ;
for(int i=1; i<=N; i++) if(P[i]>1) PQ.push({A[i][P[i]], i});
while(cnt>N/2)
{
pii now=PQ.top(); PQ.pop();
P[now.second]--; cnt--;
if(P[now.second]>1) PQ.push({A[now.second][P[now.second]], now.second});
}
for(int i=1; i<=N; i++) P[i]=max(P[i], 1);
for(int i=1; i<=N; i++) L[i]=0, R[i]=M+1;
for(int i=1; i<=K; i++)
{
vector<pii> V;
for(int j=1; j<=N; j++) V.push_back({P[j], j});
sort(V.begin(), V.end(), greater<pii>());
for(int j=1; j<=N; j++) chk[j]=0;
for(int j=0; j<N/2; j++) chk[V[j].second]=1, P[V[j].second]--;
for(int j=1; j<=N; j++)
{
if(!chk[j])
{
R[j]--;
ans+=A[j][R[j]];
ans2[j][R[j]]=i;
}
else
{
L[j]++;
ans-=A[j][L[j]];
ans2[j][L[j]]=i;
}
}
}
vector<vector<int>> answer;
answer=vector<vector<int>>(N, vector<int>(M));
for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) answer[i-1][j-1]=ans2[i][j]-1;
allocate_tickets(answer);
return ans;
}
# | 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... |