이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
#define va first
#define vb second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
const int MN = 1505;
const int MOD = 1e9+7;
const int INF = 1e9;
vector<pii> T;
int a[MN],S[MN],cur[MN],D[MN],U[MN];
int n,m;
vector<vector<int>> X;
int cal(int i, int x)
{
if(0<=x&&x<m) return X[i][x];
else return 0;
}
bool cmp(int x, int y)
{
return D[x]<D[y];
}
ll find_maximum(int k, vector<vector<int>> x) {
X = x;
n = x.size();
m = x[0].size();
ll sum = 0;
vector<vector<int>> ans;
vector<int> row(m,-1);
for(int i=0; i<n; i++){
ans.push_back(row);
}
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
T.emplace_back(x[i][j],i);
sort(all(T));
int s=0, e=n*m-1;
for(int i=0; i<n; i++){
D[i] = -1;
U[i] = m;
}
int cnt = 0;
while(cnt<n*k/2){
if(S[T[s].vb]==k) continue;
S[T[s].vb]++;
D[T[s].vb]++;
cnt++;
s++;
}
while(cnt<n*k){
if(S[T[e].vb]==k) continue;
S[T[e].vb]++;
U[T[e].vb]--;
cnt++;
e--;
}
while(1){
int val = 0;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++){
if(i==j||U[i]==m||D[j]==-1) continue;
val = (cal(i,U[i]+1)-cal(i,D[i]+1))-(cal(i,U[i])-cal(i,D[i]))
+(cal(j,U[j]-1)-cal(j,D[j]-1))-(cal(j,U[j])-cal(j,D[j]));
if(val>0){
U[i]++, D[i]++;
U[j]--, D[j]--;
break;
}
}
if(val<=0) break;
}
vector<int> v(n);
for(int i=0; i<k; i++){
for(int j=0; j<n; j++) v[j] = j;
sort(all(v),cmp);
for(int j=0; j<n; j++){
if(j>=n/2){
int c = v[j];
ans[c][D[c]] = i;
sum -= x[c][D[c]];
D[c]--;
}
else{
int c = v[j];
ans[c][U[c]] = i;
sum += x[c][U[c]];
U[c]++;
}
}
}
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... |