이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
void solve(int n, int k, vector<deque<pair<int, int>>> &T, vector<vector<int>> &ans) {
int Cnt = 0;
vector<int> cnt(n);
vector<bool> type(n);
vector<pair<int, int>> v;
for(int i = 0; i < n; i++) {
int l = T[i].front().first;
int r = T[i].back().first;
v.emplace_back(l, i);
v.emplace_back(r, i);
v.emplace_back((l + r) / 2, i);
}
sort(all(v));
for(int i = 0; i < 3 * n; i++) {
cnt[v[i].second]++;
if(cnt[v[i].second] == 2) {
Cnt++;
}
if(Cnt == n / 2) {
break;
}
}
for(int i = 0; i < 3 * n; i++) {
if(cnt[v[i].second] >= 2) // use L
type[v[i].second] = false;
else // use R
type[v[i].second] = true;
}
for(int i = 0; i < n; i++) {
if(type[i] == false) {
ans[i][T[i].front().second] = k;
T[i].pop_front();
}
else {
ans[i][T[i].back().second] = k;
T[i].pop_back();
}
}
}
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> ans;
for (int i = 0; i < n; i++) {
vector<int> row(m, -1);
ans.push_back(row);
}
vector<deque<pair<int, int>>> T(n);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
T[i].emplace_back(x[i][j], j);
}
}
for(int i = 0; i < k; i++) {
solve(n, i, T, ans);
}
// cal
long long ret = 0;
vector<vector<int>> TT(k);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(ans[i][j] != -1) {
TT[ans[i][j]].push_back(x[i][j]);
}
}
}
for(int i = 0; i < k; i++) {
sort(all(TT[i]));
int p = TT[i][n / 2];
for(int j = 0; j < n; j++) {
ret = ret + (long long)abs(p - TT[i][j]);
}
}
allocate_tickets(ans);
/*for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cout << ans[i][j] << " \n"[j == m - 1];
}
}*/
return ret;
}
# | 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... |