QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115746#5904. Twirling Towards FreedomZesty_Fox49 ✓226ms13320kbC++203.3kb2023-06-26 18:56:562023-06-26 18:56:58

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-26 18:56:58]
  • 评测
  • 测评结果:49
  • 用时:226ms
  • 内存:13320kb
  • [2023-06-26 18:56:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using u32=unsigned int;
using i64=long long;
using u64=unsigned long long;
using db=double;
using vi=vector<int>;
using pii=pair<int,int>;

template<typename T>
T read(){
    T x=0,f=0;char ch=getchar();
    while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
    while(isdigit(ch)) x=x*10+(ch-'0'),ch=getchar();
    return f?-x:x;
}

#define rdi read<int>
#define rdi64 read<i64>
#define fi first
#define se second
#define pb push_back

const int N=5010,INF=0x3f3f3f3f;
const int MX=2000;

int n,m;

struct vec{
    i64 x,y;
    vec operator+ (const vec &rhs) const{
        return {x+rhs.x,y+rhs.y};
    }
    vec operator- (const vec &rhs) const{
        return {x-rhs.x,y-rhs.y};
    }
    vec operator* (i64 k) const{
        return {x*k,y*k};
    }
    db abs() const{
        return hypot(x,y);
    }
    db arg() const{
        return atan2(y,x);
    }
    i64 cross(const vec &rhs) const{
        return x*rhs.y-y*rhs.x;
    }
    i64 dot(const vec &rhs) const{
        return x*rhs.x+y*rhs.y;
    }
    bool operator== (const vec &rhs) const{
        return x==rhs.x&&y==rhs.y;
    }
    bool operator!= (const vec &rhs) const{
        return !(*this==rhs);
    }
};

vector<vec> convex_hull(const vector<vec> &v){
    static const int M=1e6+10;
    vec mi=*min_element(v.begin(),v.end(),[&](vec a,vec b){
        return a.y!=b.y?a.y<b.y:a.x<b.x;
    });
    static int id[M];
    static db a[M],d[M];
    int sz=v.size();
    for(int i=0;i<sz;i++)
        id[i]=i,a[i]=(v[i]-mi).arg(),d[i]=(v[i]-mi).abs();
    sort(id,id+sz,[&](int x,int y){
        return fabs(a[x]-a[y])>1e-9?a[x]<a[y]:d[x]<d[y];
    });

    static vec st[1<<18|10];int tp=0;
    for(int i=0;i<sz;i++){
        vec cur=v[id[i]];
        while(tp>1&&(st[tp]-st[tp-1]).cross(cur-st[tp])<=0) --tp;
        st[++tp]=cur;
    }
    return {st+1,st+tp+1};
}

vec p[N];

template<typename T>
void ckmin(T &a,T b) {if(a>b) a=b;}
template<typename T>
void ckmax(T &a,T b) {if(a<b) a=b;}

void solve(int tid){
    n=rdi(),m=rdi();
    for(int i=1;i<=n;i++){
        int x=rdi(),y=rdi();
        p[i]={x-y,x+y};
    }
    
    vector<vec> f[5];
    f[0].pb({0,0});
    for(int i=1;i<=4;i++){
        static i64 _mi[MX*8+1],_mx[MX*8+1];
        static i64 *mi=_mi+MX*4,*mx=_mx+MX*4;
        for(int j=-MX*i;j<=MX*i;j++)
            mi[j]=INF,mx[j]=-INF;
        for(int j=1;j<=n;j++){
            vec dt;
            if(i==1) dt={p[j].x,p[j].y};
            else if(i==2) dt={p[j].y,-p[j].x};
            else if(i==3) dt={-p[j].x,-p[j].y};
            else if(i==4) dt={-p[j].y,p[j].x};
            for(auto tmp:f[i-1]){
                vec to=tmp+dt;
                mi[to.x]=min(mi[to.x],to.y);
                mx[to.x]=max(mx[to.x],to.y);
            }
        }
        for(int j=-MX*i;j<=MX*i;j++)
            if(mi[j]!=INF) f[i].pb({j,mi[j]}),f[i].pb({j,mx[j]});
        f[i]=convex_hull(f[i]);
    }

    db ans=0;
    for(int i=1;i<=min(4,m);i++){
        for(auto cur:f[i]){
            ans=max(ans,cur.abs());
            int c=(m-i)/4;
            for(auto cur1:f[4])
                ans=max(ans,(cur+cur1*c).abs());
        }
    }
    printf("Case #%d: %.10lf\n",tid,ans);
}

int main(){
    int T=rdi();
    for(int i=1;i<=T;i++) solve(i);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 8ms
memory: 10380kb

input:

100
4
1
-2 4
1 -2
4 1
0 2
1
4
-5 0
2
5
-1 1
-2 2
10
8
-842 -60
148 -967
327 -600
-546 -346
-196 -267
-833 -156
334 -791
974 -382
-499 -785
519 -657
10
7
444 786
-313 649
-377 954
-872 316
505 714
678 170
40 -971
-290 -649
-824 -797
357 -653
10
9
-384 -28
267 -243
507 -628
-189 -656
373 -879
-115 -81...

output:

Case #1: 6.3245553203
Case #2: 10.0000000000
Case #3: 6.3245553203
Case #4: 8072.6630054772
Case #5: 9582.0846374889
Case #6: 9520.9500576361
Case #7: 3136.8787034248
Case #8: 9405.6161945935
Case #9: 9809.6108995209
Case #10: 8356.3092331483
Case #11: 8863.7475144546
Case #12: 10066.9729313235
Case...

result:

ok correct! (100 test cases)

Subtask #2:

score: 39
Accepted

Test #2:

score: 39
Accepted
time: 226ms
memory: 13320kb

input:

100
200
59153573
81 -81
-252 252
864 -864
-691 691
-599 599
-520 520
-835 835
334 -334
259 -259
-469 469
374 -374
-36 36
932 -932
-518 518
-882 882
-150 150
-392 392
29 -29
8 -8
-259 259
192 -192
-863 863
-88 88
-219 219
-118 118
485 -485
-953 953
-980 980
-14 14
433 -433
-672 672
352 -352
196 -196
...

output:

Case #1: 82359120550.7561340332
Case #2: 84510626188.2999267578
Case #3: 70661053401.3009338379
Case #4: 109064878459.4080963135
Case #5: 31887461051.9420623779
Case #6: 44597031797.9429397583
Case #7: 16108038453.3387355804
Case #8: 88820696855.7596435547
Case #9: 38768573735.9652099609
Case #10: 2...

result:

ok correct! (100 test cases)

Extra Test:

score: 0
Extra Test Passed