이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define pb push_back
#define eb emplace_back
#include "tickets.h"
const int maxn = 1505;
const ll INF = 1e18;
// ll dp[maxn][maxn];
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> ans(n, vector<int>(m, -1));
ll cost = 0;
multiset<pll> stl, str; // l : l -> r, r : r -> l
vector<int> l(n), r(n);
auto rid = [&](int i) -> void {
if(l[i]) stl.erase({x[i][r[i]] + x[i][l[i] - 1], i});
if(r[i] < m - 1) str.erase({x[i][r[i] + 1] + x[i][l[i]], i});
};
auto put = [&](int i) -> void {
if(l[i]) stl.insert({x[i][r[i]] + x[i][l[i] - 1], i});
if(r[i] < m - 1) str.insert({x[i][r[i] + 1] + x[i][l[i]], i});
};
for(int i = 0; i < n; i++){
if(i < n / 2) l[i] = k, r[i] = m - 1;
else l[i] = 0, r[i] = m - 1 - k;
for(int j = 0; j < l[i]; j++) cost -= x[i][j];
for(int j = r[i] + 1; j < m; j++) cost += x[i][j];
put(i);
}
while(true){
auto [a, b] = *prev(stl.end());
auto [c, d] = *str.begin();
if(b == d || a <= c) break;
rid(b), rid(d);
// swap(ans[b][l[b] - 1], ans[b][r[b]]);
// swap(ans[d][l[d]], ans[d][r[d] + 1]);
l[b] --, r[b] --;
l[d] ++, r[d] ++;
put(b), put(d);
}
vector<int> cnt(k);
for(int i = 0; i < n; i++){
int c = 0;
set<int> used;
for(int j = 0; j < l[i]; j++){
while(cnt[c] == n / 2) c++;
ans[i][j] = c, used.insert(c);
cnt[c] ++, c++;
}
c = 0;
for(int j = r[i] + 1; j < m; j++){
while(used.count(c)) c++;
ans[i][j] = c;
c++;
}
while(used.count(c)) c++;
assert(c == n);
}
int mn = 1e9, mx = 0;
cost = 0;
vector<vector<int>> a(k);
for(int i = 0; i < n; i++){
for(int j = 0; j < l[i]; j++) cost -= x[i][j], mx = max(mx, x[i][j]);
for(int j = r[i] + 1; j < m; j++) cost += x[i][j], mn = min(mn, x[i][j]);
}
// cout<<mn<<" "<<mx<<"\n";
// assert(mn >= mx);
allocate_tickets(ans);
return cost;
}
# | 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... |