이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
long long find_maximum(int k, std::vector<std::vector<int>> a) {
int n = a.size(), m = a[0].size();
vector <int> L(n), R(n, m - 1);
vector <vector<int>> ret(n, vector <int> (m, -1));
for ( int t = 0; t < k; t++ ){
vector <ar<int,2>> p;
for ( int j = 0; j < n; j++ ){
p.pb({a[j][L[j]] + a[j][R[j]], j});
}
sort(all(p));
for ( int i = 0; i < n; i++ ){
int j = p[i][1];
if ( i < n / 2 ){
ret[j][L[j]] = t;
L[j]++;
} else{
ret[j][R[j]] = t;
R[j]--;
}
}
}
allocate_tickets(ret);
auto f = [&](auto a){
sort(all(a));
int s = a.size();
i64 cnt = 0;
for ( auto &x: a ){
cnt += abs(a[s / 2] - x);
}
return cnt;
};
vector <vector<int>> q(k);
for ( int i = 0; i < n; i++ ){
for ( int j = 0; j < m; j++ ){
if ( ret[i][j] != -1 ){
q[ret[i][j]].pb(a[i][j]);
}
}
}
i64 ans = 0;
for ( auto &x: q ){
ans += f(x);
}
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... |