QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#392059 | #2346. Miniature Golf | distant_yesterday | AC ✓ | 2359ms | 749320kb | C++20 | 5.1kb | 2024-04-17 04:09:34 | 2024-04-17 04:09:35 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include "cp_debug.h"
#else
#define debug(...) 42
#endif
#define int long long
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename T> void read(T &x){
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
read(first);
read(args...);
}
template<typename T> void write(T x) {
if(x > 9) write(x/10);
putchar(x%10 + '0');
}
signed main() {
int p, h;
read(p, h);
vector<vi> a(p, vi(h));
rep(i,0,p) {
rep(j,0,h) {
read(a[i][j]);
}
a[i].emplace_back(2e9);
sort(all(a[i]));
}
h++;
vector<vector<pii>> ops(p);
rep(i,0,p) rep(j,i+1,p) {
int si = 0, sj = 0, cl = 0, pi = 0, pj = 0;
while(pi < h || pj < h) {
int nxt = -1, slope_i = h - pi, slope_j = h - pj;
if(pj == h || (pi < h && a[i][pi] <= a[j][pj])) {
nxt = a[i][pi];
} else {
nxt = a[j][pj];
}
while(pi < h && nxt==a[i][pi]) { pi++; }
while(pj < h && nxt==a[j][pj]) { pj++; }
// cl -> nxt
assert(cl < nxt);
int end_si = si + slope_i * (nxt - cl);
int end_sj = sj + slope_j * (nxt - cl);
if(si == sj) {
if(end_si > end_sj) {
// [cl+1, nxt] j rank--
ops[j].emplace_back(cl+1, -1);
ops[j].emplace_back(nxt+1, 1);
} else if(end_si < end_sj) {
// [cl+1, nxt] i rank--
ops[i].emplace_back(cl+1, -1);
ops[i].emplace_back(nxt+1, 1);
}
} else if(si < sj) {
if(end_si < end_sj) {
// [cl+1, nxt] i rank--
ops[i].emplace_back(cl+1, -1);
ops[i].emplace_back(nxt+1, 1);
} else {
assert(slope_i > slope_j);
int diff = sj - si, slope_df = slope_i-slope_j;
if(diff % slope_df == 0) {
int v = diff / slope_df;
// [cl+1, cl+v-1] i rank--
ops[i].emplace_back(cl+1, -1);
ops[i].emplace_back(cl+v, 1);
// [cl+v+1, nxt] j rank--
ops[j].emplace_back(cl+v+1, -1);
ops[j].emplace_back(nxt+1, 1);
} else {
int v = diff / slope_df;
// [cl+1, cl+v] i rank--
ops[i].emplace_back(cl+1, -1);
ops[i].emplace_back(cl+v+1, 1);
// [cl+v+1, nxt] j rank--
ops[j].emplace_back(cl+v+1, -1);
ops[j].emplace_back(nxt+1, 1);
}
}
} else {
assert(si > sj);
if(end_si > end_sj) {
// [cl+1, nxt] j rank--
ops[j].emplace_back(cl+1, -1);
ops[j].emplace_back(nxt+1, 1);
} else {
assert(slope_i < slope_j);
int diff = si - sj, slope_df = slope_j-slope_i;
if(diff % slope_df == 0) {
int v = diff / slope_df;
// [cl+1, cl+v-1] j rank--
ops[j].emplace_back(cl+1, -1);
ops[j].emplace_back(cl+v, 1);
// [cl+v+1, nxt] i rank--
ops[i].emplace_back(cl+v+1, -1);
ops[i].emplace_back(nxt+1, 1);
} else {
int v = diff / slope_df;
// [cl+1, cl+v] j rank--
ops[j].emplace_back(cl+1, -1);
ops[j].emplace_back(cl+v+1, 1);
// [cl+v+1, nxt] i rank--
ops[i].emplace_back(cl+v+1, -1);
ops[i].emplace_back(nxt+1, 1);
}
}
}
cl = nxt;
si = end_si;
sj = end_sj;
}
}
rep(i,0,p) {
int cv = 0, mn = 0, last_pos = -1;
sort(all(ops[i]));
for(auto [pos, diff]: ops[i]) {
if(pos != last_pos) {
if(last_pos != -1) {
mn = min(mn, cv);
}
last_pos = pos;
}
cv += diff;
}
if(last_pos != -1) mn = min(mn, cv);
cout<<(p+mn)<<'\n';
}
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 1ms
memory: 3780kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3816kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3612kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 3864kb
Test #6:
score: 0
Accepted
time: 1ms
memory: 3888kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 3576kb
Test #8:
score: 0
Accepted
time: 4ms
memory: 4476kb
Test #9:
score: 0
Accepted
time: 7ms
memory: 5872kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3636kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 3772kb
Test #12:
score: 0
Accepted
time: 10ms
memory: 7712kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 3624kb
Test #14:
score: 0
Accepted
time: 2ms
memory: 3956kb
Test #15:
score: 0
Accepted
time: 8ms
memory: 7336kb
Test #16:
score: 0
Accepted
time: 8ms
memory: 3980kb
Test #17:
score: 0
Accepted
time: 2359ms
memory: 749320kb
Test #18:
score: 0
Accepted
time: 2356ms
memory: 749180kb
Test #19:
score: 0
Accepted
time: 2152ms
memory: 703156kb
Test #20:
score: 0
Accepted
time: 1258ms
memory: 379240kb
Test #21:
score: 0
Accepted
time: 1250ms
memory: 379392kb
Test #22:
score: 0
Accepted
time: 1231ms
memory: 379264kb
Test #23:
score: 0
Accepted
time: 1319ms
memory: 488284kb
Test #24:
score: 0
Accepted
time: 1308ms
memory: 477472kb
Test #25:
score: 0
Accepted
time: 1309ms
memory: 495684kb
Test #26:
score: 0
Accepted
time: 1330ms
memory: 484172kb
Test #27:
score: 0
Accepted
time: 1338ms
memory: 488444kb