QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#178264 | #2346. Miniature Golf | PetroTarnavskyi# | AC ✓ | 427ms | 4200kb | C++17 | 2.4kb | 2023-09-13 20:22:38 | 2023-09-13 20:22:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, b, a) for (int i = (b) - 1; i >= (a); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int P = 507;
const int H = 57;
const int INF = 1.1e9;
int a[P][H];
LL pref[P][H];
int p, h;
PII find_x(int i, int ii, int j, int jj)
{
if(ii == h - 1 || jj == h - 1)
return {-1, -1};
int xl = max(a[i][ii], a[j][jj]);
int xr = min(a[i][ii + 1], a[j][jj + 1]);
bool L = pref[i][ii] + 1LL * (h - ii) * xl >= pref[j][jj] + 1LL * (h - jj) * xl;
bool R = pref[i][ii] + 1LL * (h - ii) * xr >= pref[j][jj] + 1LL * (h - jj) * xr;
if(L == R)
return {-1, -1};
assert(ii != jj);
if(R)
return MP((pref[j][jj] - pref[i][ii] + jj - ii - 1) / (jj - ii), 1);
else
return MP((pref[i][ii] - pref[j][jj] + ii - jj) / (ii - jj), -1);
}
int ptr[P];
int solve(int i)
{
fill(ptr, ptr + P, 0);
int ans = p;
FOR(k, 0, h - 1)
{
//k -> k + 1;
if(a[i][k] == a[i][k + 1])
continue;
ptr[i] = k;
int bal = 0;
FOR(j, 0, p)
{
LL scI = pref[i][k] + 1LL * (h - k) * a[i][k];
LL scJ = pref[j][ptr[j]] + 1LL * (h - ptr[j]) * a[i][k];
bal += scJ <= scI;
}
vector<PII> evs;
FOR(j, 0, p)
{
if(j == i)
continue;
int nptr = ptr[j];
while(nptr + 1 < h && a[j][nptr + 1] <= a[i][k + 1])
nptr++;
//int oldsz = SZ(evs);
FOR(kj, ptr[j], nptr + 1)
{
//kj -> kj + 1
PII cur = find_x(i, k, j, kj);
if(cur.F == -1)
continue;
evs.PB(cur);
}
//assert(SZ(evs) <= oldsz + 2);
ptr[j] = nptr;
}
sort(ALL(evs));
FOR(j, 0, SZ(evs))
{
if(j == 0 || evs[j - 1].F != evs[j].F)
ans = min(ans, bal);
bal += evs[j].S;
}
ans = min(ans, bal);
}
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> p >> h;
FOR(i, 0, p)
{
FOR(j, 0, h)
cin >> a[i][j];
sort(a[i], a[i] + h);
a[i][h] = INF;
FOR(j, 0, h + 1)
{
pref[i][j] = a[i][j];
if(j > 0)
pref[i][j] += pref[i][j - 1];
}
}
h++;
FOR(i, 0, p)
{
cout << solve(i) << "\n";
}
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3692kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3624kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3852kb
Test #6:
score: 0
Accepted
time: 0ms
memory: 3648kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 3652kb
Test #8:
score: 0
Accepted
time: 1ms
memory: 3612kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 3892kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3592kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 3668kb
Test #12:
score: 0
Accepted
time: 3ms
memory: 3660kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 3856kb
Test #14:
score: 0
Accepted
time: 1ms
memory: 3612kb
Test #15:
score: 0
Accepted
time: 3ms
memory: 3660kb
Test #16:
score: 0
Accepted
time: 44ms
memory: 4188kb
Test #17:
score: 0
Accepted
time: 402ms
memory: 4004kb
Test #18:
score: 0
Accepted
time: 427ms
memory: 4044kb
Test #19:
score: 0
Accepted
time: 404ms
memory: 4200kb
Test #20:
score: 0
Accepted
time: 181ms
memory: 3944kb
Test #21:
score: 0
Accepted
time: 178ms
memory: 4012kb
Test #22:
score: 0
Accepted
time: 182ms
memory: 3980kb
Test #23:
score: 0
Accepted
time: 212ms
memory: 3876kb
Test #24:
score: 0
Accepted
time: 217ms
memory: 3924kb
Test #25:
score: 0
Accepted
time: 215ms
memory: 3988kb
Test #26:
score: 0
Accepted
time: 212ms
memory: 4188kb
Test #27:
score: 0
Accepted
time: 215ms
memory: 3984kb