이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;
struct el {
long long x, y, idx;
bool operator < (const el &oth) const {
return y + x < oth.x + oth.y;
}
};
struct val {
long long v, x, y;
bool operator < (const val &oth) const {
if (v == oth.v) return x < oth.x;
return v < oth.v;
}
};
// bool comp (pair <long, long> a, pair <long, long> b) {
// if (a.first != b.first) return a.first <
// }
long long find_maximum(int k, vector<vector<int>> x) {
long long n = x.size();
long long m = x[0].size();
long long rs = 0;
vector <int> times (n, 1);
vector <vector <int> > answer (n, vector <int> (m, -1));
vector <vector <bool> > take (n, vector <bool> (m, 0));
priority_queue <el> pq;
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++){
rs-=x[i][j];
take[i][j] = 1;
}
pq.push({x[i][k-1], x[i][m-1], i});
}
for (int z = 0; z < n * k / 2; z++){
el now = pq.top();
pq.pop();
rs+=now.x + now.y;
take[now.idx][k - times[now.idx]] = 0;
take[now.idx][m - times[now.idx]] = 1;
if (times[now.idx] != k) {
times[now.idx]++;
now.x = x[now.idx][k - times[now.idx]];
now.y = x[now.idx][m - times[now.idx]];
pq.push(now);
}
}
vector <val> v;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (take[i][j]) {
v.push_back({x[i][j], i, j});
}
}
}
sort(v.begin(), v.end());
// for (auto i: v){
// cout << i.v << " " <<i.x << " " << i.y << "\n";
// }
vector <int> col (n);
vector <set <int> > nt (n, set <int> ());
vector <pair <int, int> > suka;
for (int i = 0; i < n * k / 2; i++){
suka.push_back({v[i].x, v[i].y});
}
sort(suka.begin(), suka.end());
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++){
nt[i].insert(j);
}
}
for (int i = 0; i < n * k / 2; i++){
answer[suka[i].first][suka[i].second] = i % k;
nt[suka[i].first].erase(i % k);
}
for (int i = n * k / 2; i < n * k; i++){
answer[v[i].x][v[i].y] = *nt[v[i].x].begin();
nt[v[i].x].erase(nt[v[i].x].begin());
}
allocate_tickets(answer);
return rs;
}
# | 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... |