이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
#define MINUS 2*MOD+2
#define PLUS MOD+1
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vi> answer(n);
vector<multiset<int> > rem(n);
answer.assign(n, vector<int>(m, -1));
FOR(i,n) FOR(j,m) rem[i].insert(x[i][j]);
/*
FOR(i,n){
FOA(v,rem[i]) cout<<v<<" ";
cout<<endl;
}*/
ll ans=0;
FOR(round,k){
vii maxa, mina;
FOR(i,n){
if(rem[i].size())
maxa.push_back({ - *rem[i].begin() - *(--rem[i].end()), i});
}
sort(maxa.begin(), maxa.end());
FOR(i,n){
int t = *rem[i].begin();
//cout<<t<<endl;
FOR(j,m) if(x[i][j]==t && answer[i][j]==-1){
//cout<<i<<" "<<j<<endl;
answer[i][j] = MINUS+round;
break;
}
ans -= t;
}
FOR(i,n/2){
assert(rem[maxa[i].S].size());
int t = *(--rem[maxa[i].S].end());
int tp = *(rem[maxa[i].S].begin());
//cout<<"rem "<<tp<<" add "<<t<<endl;
assert(maxa[i].F==-t-tp);
ans -= maxa[i].F;
FOR(j,m) if(x[maxa[i].S][j]==tp && answer[maxa[i].S][j]==MINUS+round){
answer[maxa[i].S][j] = -1;
break;
}
FOR(j,m) if(x[maxa[i].S][j]==t && answer[maxa[i].S][j]==-1){
answer[maxa[i].S][j] = PLUS+round;
break;
}
}
FOR(i,n){
FOR(j,m){
//cout<<answer[i][j]<<" ";
if(answer[i][j]==MINUS+round || answer[i][j]==PLUS+round){
if(rem[i].find(x[i][j])!=rem[i].end())
rem[i].erase(rem[i].find(x[i][j]));
}
}
//cout<<i<<": ";
//FOA(v, rem[i]) cout<<v<<" ";
//cout<<endl;
}
/*
FOR(i,n){
FOR(j,m){
if(answer[i][j]>=MINUS) cout<<" - ";
else if(answer[i][j]>=PLUS && answer[i][j]<=MINUS) cout<<" + ";
else cout<<answer[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;*/
}
//cout<<"--------------\n";
FOR(rnd,k){
vector<iii> pc;
FOR(i,n){
int p=0;
int lp=0;
FOR(j,m) if(answer[i][j]>=PLUS && answer[i][j]<MINUS) p++, lp=j;
pc.push_back({{-p,i},lp});
}
sort(pc.begin(), pc.end());
set<int> used;
FOR(i,n/2){
used.insert(pc[i].F.S);
//cout<<pc[i].F.S<<" "<<pc[i].S<<endl;
// use n/2 PLUSs
answer[pc[i].F.S][pc[i].S] = rnd;
}
FOR(i,n) if(!used.count(i)){
bool f = false;
FOR(j,m) if(answer[i][j]>=MINUS){
answer[i][j] = rnd;
f = true;
break;
}
assert(f);
}
/*
FOR(i,n){
FOR(j,m) cout<<answer[i][j]<<" ";
cout<<endl;
}*/
}
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... |