QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#265945#2346. Miniature GolfInfinityNS#AC ✓1839ms5656kbC++142.7kb2023-11-25 22:52:192023-11-25 22:52:19

Judging History

你现在查看的是最新测评结果

  • [2023-11-25 22:52:19]
  • 评测
  • 测评结果:AC
  • 用时:1839ms
  • 内存:5656kb
  • [2023-11-25 22:52:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

const int N=505;
const int H=55;
int a[N][H],n,h;
const ll lim=1e18;

ll GetVal(int i,int isz,int j,int jsz){
    if(isz>h && jsz>h)return lim;
    if(isz>h || (jsz<=h && a[i][isz]>a[j][jsz])){
        return a[j][jsz];
    }else{
        return a[i][isz];
    }
}

ll Get(int k,ll n,ll x){
    return x*k+n;
}

vector<pair<ll,int>> evs;
void AddInterval(ll L, ll R){
    //printf("Add interval [%lld %lld]\n",L,R);
    evs.pb({L,1});
    evs.pb({R+1,-1});
}

ll Inter1(int ik,ll in,int jk,ll jn){
    ll dn=in-jn;
    ll dk=jk-ik;
    if(dk<0)dk=-dk,dn=-dn;
    return dn/dk;
}

ll Inter2(int ik,ll in,int jk,ll jn){
    ll dn=in-jn;
    ll dk=jk-ik;
    if(dk<0)dk=-dk,dn=-dn;
    return (dn+dk-1)/dk;
}

void Solve(int ik,ll in,int jk,ll jn,ll from,ll to){
    if(from>to)return;
    //printf("Solve [%lld %lld]\n",from,to);

    ll fi=Get(ik,in,from);
    ll fj=Get(jk,jn,from);
    ll ti=Get(ik,in,to);
    ll tj=Get(jk,jn,to);

    if(fi>=fj && ti>=tj){
        AddInterval(from,to);
    }else if(fi>=fj){
        AddInterval(from,Inter1(ik,in,jk,jn));
    }else if(ti>=tj){
        AddInterval(Inter2(ik,in,jk,jn),to);
    }
}
int main(){
    scanf("%i %i",&n,&h);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=h;j++){
            scanf("%i",&a[i][j]);
        }
        sort(a[i]+1,a[i]+1+h);
    }
    for(int i=1;i<=n;i++){
        evs.clear();
        for(int j=1;j<=n;j++){
            if(i==j)continue;
            int isz=1,jsz=1;
            ll in=0,jn=0;
            int ik=h,jk=h;
            ll from=1,to=GetVal(i,isz,j,jsz)-1;
            Solve(ik,in,jk,jn,from,to);
            while(isz<=h || jsz<=h){
                ll val=GetVal(i,isz,j,jsz);

                while(isz<=h && a[i][isz]==val){
                    ik--;
                    in+=a[i][isz];
                    isz++;
                }
                while(jsz<=h && a[j][jsz]==val){
                    jk--;
                    jn+=a[j][jsz];
                    jsz++;
                }

                ll from=val,to=GetVal(i,isz,j,jsz)-1;

                Solve(ik,in,jk,jn,from,to);
            }
        }
        evs.pb({1,1});
        evs.pb({lim,1});
        sort(evs.begin(),evs.end());
        int now=0;
        ll last=1;
        int ans=n;
        for(auto ev:evs){
            if(last<ev.first){
                //printf("(%lld %lld) -> %i\n",last,ev.first-1,now);
                ans=min(ans,now);
            }
            now+=ev.second;
            last=ev.first;
        }
        printf("%i\n",ans);
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3788kb

Test #2:

score: 0
Accepted
time: 0ms
memory: 3756kb

Test #3:

score: 0
Accepted
time: 0ms
memory: 3868kb

Test #4:

score: 0
Accepted
time: 0ms
memory: 3856kb

Test #5:

score: 0
Accepted
time: 0ms
memory: 3872kb

Test #6:

score: 0
Accepted
time: 0ms
memory: 3768kb

Test #7:

score: 0
Accepted
time: 0ms
memory: 3800kb

Test #8:

score: 0
Accepted
time: 3ms
memory: 4064kb

Test #9:

score: 0
Accepted
time: 7ms
memory: 3896kb

Test #10:

score: 0
Accepted
time: 0ms
memory: 3932kb

Test #11:

score: 0
Accepted
time: 1ms
memory: 3816kb

Test #12:

score: 0
Accepted
time: 12ms
memory: 3928kb

Test #13:

score: 0
Accepted
time: 0ms
memory: 3864kb

Test #14:

score: 0
Accepted
time: 2ms
memory: 3972kb

Test #15:

score: 0
Accepted
time: 12ms
memory: 3916kb

Test #16:

score: 0
Accepted
time: 27ms
memory: 4028kb

Test #17:

score: 0
Accepted
time: 1839ms
memory: 5540kb

Test #18:

score: 0
Accepted
time: 1822ms
memory: 5456kb

Test #19:

score: 0
Accepted
time: 1728ms
memory: 5524kb

Test #20:

score: 0
Accepted
time: 1717ms
memory: 5436kb

Test #21:

score: 0
Accepted
time: 1719ms
memory: 5632kb

Test #22:

score: 0
Accepted
time: 1710ms
memory: 5476kb

Test #23:

score: 0
Accepted
time: 1358ms
memory: 5520kb

Test #24:

score: 0
Accepted
time: 1356ms
memory: 5440kb

Test #25:

score: 0
Accepted
time: 1351ms
memory: 5512kb

Test #26:

score: 0
Accepted
time: 1362ms
memory: 5656kb

Test #27:

score: 0
Accepted
time: 1358ms
memory: 5460kb