QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#537056 | #2346. Miniature Golf | arnold518 | AC ✓ | 1776ms | 267856kb | C++17 | 3.6kb | 2024-08-29 19:01:46 | 2024-08-29 19:01:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 500;
const int MAXM = 50;
int N, M;
int A[MAXN+10][MAXM+10];
ll divceil(ll u, ll d) { return u/d+((u^d)>0 && u%d); }
int ans[MAXN+10];
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> N >> M;
vector<pll> V2;
vector<ll> V3;
for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) cin >> A[i][j], V3.push_back(A[i][j]);
for(int i=1; i<=N; i++) sort(A[i]+1, A[i]+M+1);
for(int i=1; i<=N; i++)
{
for(int j=i+1; j<=N; j++)
{
vector<pll> V;
for(int k=1; k<=M; k++) V.push_back({A[i][k], 0});
for(int k=1; k<=M; k++) V.push_back({A[j][k], 1});
inplace_merge(V.begin(), V.begin()+M, V.end());
ll sa=M, sb=M;
ll ya=0, yb=0, x=0;
for(int l=0, r=0; l<V.size(); l=r)
{
ya+=(V[l].first-x)*sa;
yb+=(V[l].first-x)*sb;
x=V[l].first;
for(; r<V.size() && V[r].first==V[l].first; r++)
{
if(V[r].second==0) sa--;
else sb--;
}
if(r<V.size())
{
ll xl=V[l].first, xr=V[r].first;
if(sa==sb) continue;
ll xp=divceil(yb-ya, sa-sb)+xl;
if(xl<xp && xp<xr)
{
if(ya<yb)
{
V2.push_back({xp, i});
V2.push_back({xp+((yb-ya)%(sa-sb)==0 ? 1 : 0), -j});
}
else
{
V2.push_back({xp, j});
V2.push_back({xp+((yb-ya)%(sa-sb)==0 ? 1 : 0), -i});
}
}
else if(ya==yb)
{
if(sa<sb) V2.push_back({xl+1, -i});
else V2.push_back({xl+1, -j});
}
}
}
}
}
sort(V3.begin(), V3.end());
sort(V2.begin(), V2.end());
V3.erase(unique(V3.begin(), V3.end()), V3.end());
int pos[N+1]{};
ll sum[N+1]{};
for(int i=1; i<=N; i++) ans[i]=N, pos[i]=1;
for(int i=0, j=0; i<V3.size(); i++)
{
vector<pll> VV;
for(int k=1; k<=N; k++)
{
for(; pos[k]<=M && A[k][pos[k]]<=V3[i]; pos[k]++) sum[k]+=A[k][pos[k]];
ll t=sum[k]+1ll*(M-pos[k]+1)*V3[i];
VV.push_back({t, k});
}
sort(VV.begin(), VV.end());
int rnk[N+1]{};
for(int l=0, r=0; l<VV.size(); l=r)
{
for(; r<VV.size() && VV[r].first==VV[l].first; r++);
for(int p=l; p<r; p++) rnk[VV[p].second]=r;
}
for(int p=1; p<=N; p++) ans[p]=min(ans[p], rnk[p]);
if(i+1==V3.size()) break;
for(; j<V2.size() && V2[j].first<=V3[i]; j++);
for(int r=j; j<V2.size() && V2[j].first<V3[i+1]; j=r)
{
for(; r<V2.size() && V2[r].first<V3[i+1] && V2[j].first==V2[r].first; r++)
{
if(V2[r].second>0) rnk[V2[r].second]++;
else rnk[-V2[r].second]--;
}
for(int p=j; p<r; p++)
{
int t=abs(V2[p].second);
ans[t]=min(ans[t], rnk[t]);
}
}
}
for(int i=1; i<=N; i++) cout << ans[i] << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3632kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3836kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3796kb
Test #6:
score: 0
Accepted
time: 0ms
memory: 3612kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 3508kb
Test #8:
score: 0
Accepted
time: 1ms
memory: 3880kb
Test #9:
score: 0
Accepted
time: 3ms
memory: 3708kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3556kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 3628kb
Test #12:
score: 0
Accepted
time: 5ms
memory: 3968kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 3556kb
Test #14:
score: 0
Accepted
time: 1ms
memory: 3684kb
Test #15:
score: 0
Accepted
time: 5ms
memory: 3744kb
Test #16:
score: 0
Accepted
time: 111ms
memory: 3856kb
Test #17:
score: 0
Accepted
time: 1749ms
memory: 266560kb
Test #18:
score: 0
Accepted
time: 1776ms
memory: 267220kb
Test #19:
score: 0
Accepted
time: 1543ms
memory: 267856kb
Test #20:
score: 0
Accepted
time: 513ms
memory: 71288kb
Test #21:
score: 0
Accepted
time: 503ms
memory: 71188kb
Test #22:
score: 0
Accepted
time: 505ms
memory: 69464kb
Test #23:
score: 0
Accepted
time: 455ms
memory: 8732kb
Test #24:
score: 0
Accepted
time: 459ms
memory: 9376kb
Test #25:
score: 0
Accepted
time: 451ms
memory: 8600kb
Test #26:
score: 0
Accepted
time: 453ms
memory: 9392kb
Test #27:
score: 0
Accepted
time: 456ms
memory: 9104kb