이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll , ll> ii;
#define ff first
#define ss second
#define pb push_back
#define in insert
long long find_maximum(int k, std::vector<std::vector<int>> x) {
ll n = x.size();
ll m = x[0].size();
vector < vector < int > > answer(n, vector < int >(m, -1));
vector < vector < int > > neg(n, vector < int >(m, 0));
vector < vector < int > > pos(n, vector < int >(m, 0));
vector < ll > curX(n, k-1);
vector < ll > curY(n, m);
ll ans = 0;
priority_queue < ii > p;
for(ll i = 0; i < n; i++){
for(ll j = 0; j < m; j++){
if(j < k) neg[i][j] = 1, ans -= x[i][j];
}
if(curX[i] >= 0){
p.push({x[i][curX[i]] + x[i][curY[i] - 1], i});
}
}
for(ll itr = 0; itr < (k * n)/2; itr++){
auto [value, i] = p.top(); p.pop();
ans += value;
neg[i][curX[i]] = 0;
pos[i][curY[i] - 1] = 1;
curY[i]--;
curX[i]--;
if(curX[i] >= 0){
p.push({x[i][curX[i]] + x[i][curY[i] - 1], i});
}
}
vector < ll > P[n + 10], N[n + 10];
for(ll i = 0; i < n; i++){
for(ll j = 0; j < m; j++){
if(neg[i][j]) N[i].pb(j);
if(pos[i][j]) P[i].pb(j);
}
}
for(ll itr = 0; itr < k; itr++){
ll tot = 0;
vector < ll > done(n, 0);
for(ll i = 0; i < n; i++){
if(!N[i].size()){
auto T = P[i].back(); P[i].pop_back();
answer[i][T] = itr;
done[i] = 1; tot++;
}else if(!P[i].size()){
auto T = N[i].back(); N[i].pop_back();
answer[i][T] = itr;
done[i] = 1;
}
}
for(ll i = 0; i < n; i++){
if(done[i]) continue;
if(tot < n/2){
auto T = P[i].back(); P[i].pop_back();
answer[i][T] = itr;
done[i] = 1; tot++;
}else{
auto T = N[i].back(); N[i].pop_back();
answer[i][T] = itr;
done[i] = 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... |