QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#415771#4226. Cookie CutterlittlecatWA 1ms3908kbC++143.1kb2024-05-21 09:54:002024-05-21 09:54:01

Judging History

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

  • [2024-05-21 09:54:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3908kb
  • [2024-05-21 09:54:00]
  • 提交

answer

#pragma GCC optimize("O3")
#include <iostream>
using namespace std;
#include <vector>
#define pb push_back
template<class C> using vc=vector<C>;
#include <algorithm>
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define smax(a,b) a=max(a,b)
#define f first
#define s second
const int mx=3000;
typedef double d;
typedef pair<int,int> pi;
typedef pair<d,int> pdi;
int n; pi P[mx];
d area(int i, int j)
{
    //area/n^2 of right side; guaranteed not vertical
    bool f=P[j].f<P[i].f;
    if(f) swap(i,j); //j is on the right
    d ans=0;
    //left of i
    if(P[j].s*P[i].f>=P[i].s*P[j].f)
        ans+=P[i].s*(P[j].f-P[i].f)*.5*P[i].s/(P[j].s-P[i].s);
    else if((n-P[j].s)*P[i].f>=(n-P[i].s)*P[j].f)
        ans+=(n-P[i].s)*(P[j].f-P[i].f)*.5*(n-P[i].s)/(P[i].s-P[j].s);
    else ans+=P[i].f*.5*(2*P[i].s+(P[i].s-P[j].s)*P[i].f*1./(P[j].f-P[i].f));
    //flip, left of j'
    P[i].f=n-P[i].f, P[j].f=n-P[j].f; swap(i,j);
    if(P[j].s*P[i].f>=P[i].s*P[j].f)
        ans+=P[i].s*(P[j].f-P[i].f)*.5*P[i].s/(P[j].s-P[i].s);
    else if((n-P[j].s)*P[i].f>=(n-P[i].s)*P[j].f)
        ans+=(n-P[i].s)*(P[j].f-P[i].f)*.5*(n-P[i].s)/(P[i].s-P[j].s);
    else ans+=P[i].f*.5*(2*P[i].s+(P[i].s-P[j].s)*P[i].f*1./(P[j].f-P[i].f));
    //flip back + trapezoid
    P[i].f=n-P[i].f, P[j].f=n-P[j].f; swap(i,j);
    ans+=(P[j].f-P[i].f)*.5*(P[i].s+P[j].s);
    ans/=n*n; if(f) return 1-ans; return ans;
}
int main()
{
    cin.sync_with_stdio(0), cin.tie(0), cout.sync_with_stdio(0), cout.tie(0);
    int m; cin>>n>>m;
    For(i,0,m) cin>>P[i].f>>P[i].s;
    d ans=0;
    For(i,0,m)
    {
        vc<pdi> v;
        For(j,0,m) if(P[j].f!=P[i].f)
            v.pb({(P[j].s-P[i].s)*1./(P[j].f-P[i].f),(j+1)*(1-2*(P[j].f>P[i].f))});
        sort(v.begin(),v.end());
        int cnt=0, up=0, down=0;
        For(j,0,m)
            if(P[j].f!=P[i].f) cnt+=P[j].f<P[i].f;
            else cnt+=P[j].s<=P[i].s, down+=P[j].s<P[i].s, up+=P[j].s>P[i].s;
        //vertical line
        smax(ans,(cnt+up)*1./m-P[i].f*1./n);
        smax(ans,(m-cnt+down+1)*1./m-(n-P[i].f)*1./n);
        //rotate around i
        for(pdi p:v)
        {
            int j=abs(p.s)-1; cnt+=2*(P[j].f>P[i].f)-1;
            if(P[j].f>P[i].f)
                smax(ans,cnt*1./m-area(i,j)),
                smax(ans,(m-cnt+2)*1./m-area(j,i));
            else
                smax(ans,cnt*1./m-area(j,i)),
                smax(ans,(m-cnt+2)*1./m-area(i,j));
        }
        //corner piece: unique line
        bool fx=P[i].f*2>n, fy=P[i].s*2>n;
        if(fx) For(j,0,m) P[j].f=n-P[j].f;
        if(fy) For(j,0,m) P[j].s=n-P[j].s;
        cnt=0; For(j,0,m) cnt+=P[j].f*P[i].s+P[j].s*P[i].f<=2*P[i].f*P[i].s;
        smax(ans,cnt*1./m-P[i].f*P[i].s*2./(n*n));
        if(fx) For(j,0,m) P[j].f=n-P[j].f;
        if(fy) For(j,0,m) P[j].s=n-P[j].s;
    }
    cout<<ans<<'\n';
}
//if opposite sides (left/right): area = n(x+y)/2
//get point at (u,v) iff x(n-u) + yu >= nv (x = left)
//m lines of negative slope; LP
//or order statistics with O(m^2) flips
//if adjacent sides: area = xy/2 (or n^2-xy/2)
//get point at (u,v) iff (x-u)(y-v)>=uv, x>=u, y>=v...

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3908kb

input:

5 8
1 1
1 2
1 3
2 1
3 1
3 4
4 1
4 2

output:

0.83

result:

wrong answer 1st numbers differ - expected: '0.3750000', found: '0.8300000', error = '0.4550000'