이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include "bits/stdc++.h"
using namespace std;
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row(m);
for (int j = 0; j < m; j++) {
row[j] = -1;
}
answer.push_back(row);
}
priority_queue<pair<int, pair<int, int > > > pq;
long long ans = 0;
int chosen[n];
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
pq.push({x[i][j], {i, j}});
}
}
for(int i=0; i<n; i++) chosen[i] = 0;
int cnt = 0;
while(pq.size()) {
if(chosen[pq.top().second.first] == k) {
pq.pop(); continue;
}
chosen[pq.top().second.first]++;
answer[pq.top().second.first][pq.top().second.second] = 1; // 1: add, -2: subtract, -1: not chosen
ans += pq.top().first;
pq.pop();
cnt++;
if(cnt == n*k / 2) break;
}
while(pq.size()) pq.pop();
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
pq.push({-x[i][j], {i, j}});
}
}
cnt = 0;
while(pq.size()) {
if(chosen[pq.top().second.first] == k || answer[pq.top().second.first][pq.top().second.second] == 1) {
pq.pop(); continue;
}
chosen[pq.top().second.first]++;
answer[pq.top().second.first][pq.top().second.second] = -2; // 1: add, -2: subtract, -1: not chosen
ans += pq.top().first;
pq.pop();
cnt++;
if(cnt == n*k / 2) break;
}
while(pq.size()) pq.pop();
int nxt = 0;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if(answer[i][j] == 1) {
answer[i][j] = nxt;
nxt = (nxt + 1) % k;
}
}
}
for(int i=0; i<n; i++) {
bool bruh[m];
for(int j=0; j<m; j++) bruh[j] = 0;
for(int j=0; j<m; j++) if(answer[i][j] >= 0) bruh[answer[i][j]] = 1;
nxt = 0;
for(int j=0; j<m; j++) {
if(answer[i][j] == -2) {
while(bruh[nxt]) nxt++;
bruh[nxt] = 1;
answer[i][j] = nxt;
}
}
}
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... |