이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;
typedef long long ll;
struct dat{
int i, l, r; ll val;
dat(){}
dat(int i, int l, int r, ll val): i(i), l(l), r(r), val(val){}
bool operator<(const dat &tr)const{
if(val == tr.val) return l < tr.l;
return val < tr.val;
}
};
vector<vector<int> > ans;
ll ansV;
vector<dat> vec;
queue<int> small[1502], big[1502];
int only[1502]; /// 0: all, 1: only small, 2: only big
ll find_maximum(int k, vector<vector<int>> x) {
int n = x.size(), nh = n/2;
int m = x[0].size();
ans.resize(n);
for(int i=0; i<n; i++) ans[i] = vector<int>(m, -1);
for(int i=0; i<n; i++){
for(int j=0; j<k; j++){
ansV += x[i][m-k+j];
vec.push_back(dat(i, j, m-k+j, x[i][j] + x[i][m-k+j]));
big[i].push(m-k+j);
}
}
sort(vec.begin(), vec.end());
for(int i=0; i<nh*k; i++){
dat tmp = vec[i];
ansV -= tmp.val;
assert(big[tmp.i].front() == tmp.r);
big[tmp.i].pop();
small[tmp.i].push(tmp.l);
}
for(int c=0; c<k; c++){
for(int i=0; i<n; i++){
if(big[i].empty()) only[i] = 1;
else if(small[i].empty()) only[i] = 2;
else only[i] = 0;
}
int smallCnt = 0, bigCnt = 0;
for(int i=0; i<n; i++){
if(!only[i]) continue;
if(only[i] == 1){
ans[i][small[i].front()] = c;
small[i].pop(), smallCnt++;
}
else{
ans[i][big[i].front()] = c;
big[i].pop(), bigCnt++;
}
}
for(int i=0; i<n; i++){
if(only[i]) continue;
if(smallCnt < nh){
ans[i][small[i].front()] = c;
small[i].pop(), smallCnt++;
}
else{
ans[i][big[i].front()] = c;
big[i].pop(), bigCnt++;
}
}
}
allocate_tickets(ans);
return ansV;
}
# | 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... |