이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I can do all things through Christ who strengthens me
// Philippians 4:13
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define REP(i, j, k) for (int i = j; i < (k); i++)
#define RREP(i, j, k) for (int i = j; i >= (k); i--)
template <class T>
inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
const int MAXN = 1505;
int n, m, k;
vector<vi> x, s;
int l[MAXN], r[MAXN];
ii diff[MAXN];
vi grp[MAXN][2];
ll ans;
ll find_maximum(int _k, vector<vi> _x) {
k = _k; x = _x;
n = SZ(x); m = SZ(x[0]);
s = vector<vi>(n, vi(m, -1));
if (k == m) {
viii vx;
REP (i, 0, n) {
REP (j, 0, m) {
vx.pb({x[i][j], i, j});
}
}
sort(ALL(vx));
REP (p, 0, n * m) {
auto [x, i, j] = vx[p];
if (p < n / 2 * m) {
ans -= x;
grp[i][0].pb(j);
} else {
ans += x;
grp[i][1].pb(j);
}
}
REP (z, 0, k) {
int cnt[2] = {0, 0};
REP (i, 0, n) {
if (grp[i][0].empty()) {
cnt[1]++;
int j = grp[i][1].back(); grp[i][1].pop_back();
s[i][j] = z;
} else if (grp[i][1].empty()) {
cnt[0]++;
int j = grp[i][0].back(); grp[i][0].pop_back();
s[i][j] = z;
}
}
REP (i, 0, n) {
if (grp[i][0].empty() || grp[i][1].empty()) {
continue;
}
REP (l, 0, 2) {
if (cnt[l] == n / 2) {
continue;
}
cnt[l]++;
int j = grp[i][l].back(); grp[i][l].pop_back();
s[i][j] = z;
}
}
}
allocate_tickets(s);
return ans;
}
REP (i, 0, n) {
l[i] = 0, r[i] = m - 1;
}
REP (z, 0, k) {
REP (i, 0, n) {
ans += x[i][r[i]];
diff[i] = {x[i][r[i]] + x[i][l[i]], i};
s[i][r[i]--] = z;
}
sort(diff, diff + n);
REP (i, 0, n / 2) {
ans -= diff[i].FI;
s[diff[i].SE][++r[diff[i].SE]] = -1;
s[diff[i].SE][l[diff[i].SE]++] = z;
}
}
allocate_tickets(s);
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... |