QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#483307 | #2346. Miniature Golf | karuna | AC ✓ | 1393ms | 105148kb | C++20 | 3.2kb | 2024-07-18 15:16:07 | 2024-07-18 15:16:07 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int SZ = 505;
int n, h, a[SZ][SZ], g[SZ][SZ], ans[SZ], c[SZ];
pii ev[30303030];
int f(int u, int v, int t) {
return 3 * n * u + 3 * v + t;
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> h;
for (int i = 0; i < n; i++) {
for (int j = 0; j < h; j++) {
cin >> a[i][j];
}
sort(a[i], a[i] + h);
}
int sp = 0;
auto add = [&](pii elt) {
if (sp == 0 || ev[sp - 1].ss != elt.ss) ev[sp++] = elt;
};
for (int u = 0; u < n; u++) {
for (int v = 0; v < u; v++) {
int el = 3 * n * u + 3 * v;
ll s = 0, t = 0;
int prv = 0;
for (int i = 0, j = 0, p = 0, q = 0; i < h || j < h; i = p, j = q) {
int mn = 1e9;
if (i != h) mn = min(mn, a[u][i]);
if (j != h) mn = min(mn, a[v][j]);
while (p < h && a[u][p] == mn) ++p;
while (q < h && a[v][q] == mn) ++q;
ll a = h - i;
ll b = h - j;
ll x = s;
ll y = a * (mn - prv) + s;
ll z = t;
ll w = b * (mn - prv) + t;
if (x == z) {
add({prv, el + 1});
if (prv + 1 != mn) {
if (y > w) add({prv + 1, el + 2});
if (y < w) add({prv + 1, el + 0});
}
}
else if (x > z) {
if (y >= w) add({prv, el + 2});
else {
ll p = s - t;
ll q = b - a;
if (q < 0) p *= -1, q *= -1;
if (p % q == 0) {
add({prv, el + 2});
add({prv + p / q, el + 1});
if (prv + p / q + 1 != mn) add({prv + p / q + 1, el + 0});
}
else {
ll x = prv + p / q;
add({prv, el + 2});
if (x + 1 != mn) add({x + 1, el + 0});
}
}
}
else {
if (y <= w) add({prv, el + 0});
else {
ll p = s - t;
ll q = b - a;
if (q < 0) p *= -1, q *= -1;
if (p % q == 0) {
add({prv, el + 0});
add({prv + p / q, el + 1});
if (prv + p / q + 1 != mn) add({prv + p / q + 1, el + 2});
}
else {
ll x = prv + p / q;
add({prv, el + 0});
if (x + 1 != mn) add({x + 1, el + 2});
}
}
}
s += 1ll * (h - i) * (mn - prv);
t += 1ll * (h - j) * (mn - prv);
prv = mn;
}
if (s < t) add({prv, el + 0});
if (s == t) add({prv, el + 1});
if (s > t) add({prv, el + 2});
}
}
sort(ev, ev + sp);
for (int v = 0; v < n; v++) ans[v] = n;
for (int u = 0; u < n; u++) {
for (int v = 0; v < u; v++) {
g[u][v] = 1;
c[u]++;
c[v]++;
}
}
for (int i = 0, p = 0; i < sp; i = p) {
while (p < sp && ev[i].ff == ev[p].ff) {
int u = ev[p].ss / (3 * n);
int v = ev[p].ss / 3 % n;
int t = ev[p].ss % 3;
if (g[u][v] == 0) --c[v];
if (g[u][v] == 1) --c[u], --c[v];
if (g[u][v] == 2) --c[u];
g[u][v] = t;
if (g[u][v] == 0) ++c[v];
if (g[u][v] == 1) ++c[u], ++c[v];
if (g[u][v] == 2) ++c[u];
++p;
}
for (int j = i; j < p; j++) {
int u = ev[j].ss / (3 * n);
int v = ev[j].ss / 3 % n;
ans[u] = min(ans[u], c[u]);
ans[v] = min(ans[v], c[v]);
}
}
for (int v = 0; v < n; v++) cout << ans[v] + 1 << '\n';
}
Details
Test #1:
score: 100
Accepted
time: 1ms
memory: 5568kb
Test #2:
score: 0
Accepted
time: 1ms
memory: 5556kb
Test #3:
score: 0
Accepted
time: 1ms
memory: 5648kb
Test #4:
score: 0
Accepted
time: 1ms
memory: 5760kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 5592kb
Test #6:
score: 0
Accepted
time: 1ms
memory: 5632kb
Test #7:
score: 0
Accepted
time: 1ms
memory: 5664kb
Test #8:
score: 0
Accepted
time: 0ms
memory: 5672kb
Test #9:
score: 0
Accepted
time: 2ms
memory: 5700kb
Test #10:
score: 0
Accepted
time: 1ms
memory: 5612kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 5616kb
Test #12:
score: 0
Accepted
time: 3ms
memory: 5820kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 5612kb
Test #14:
score: 0
Accepted
time: 1ms
memory: 5664kb
Test #15:
score: 0
Accepted
time: 3ms
memory: 5804kb
Test #16:
score: 0
Accepted
time: 13ms
memory: 8116kb
Test #17:
score: 0
Accepted
time: 1393ms
memory: 105148kb
Test #18:
score: 0
Accepted
time: 1347ms
memory: 103028kb
Test #19:
score: 0
Accepted
time: 1159ms
memory: 86572kb
Test #20:
score: 0
Accepted
time: 683ms
memory: 51756kb
Test #21:
score: 0
Accepted
time: 678ms
memory: 49772kb
Test #22:
score: 0
Accepted
time: 681ms
memory: 51892kb
Test #23:
score: 0
Accepted
time: 156ms
memory: 10860kb
Test #24:
score: 0
Accepted
time: 158ms
memory: 8848kb
Test #25:
score: 0
Accepted
time: 158ms
memory: 10996kb
Test #26:
score: 0
Accepted
time: 161ms
memory: 8856kb
Test #27:
score: 0
Accepted
time: 160ms
memory: 10848kb