QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#415741 | #4226. Cookie Cutter | littlecat# | WA | 0ms | 3804kb | C++14 | 2.8kb | 2024-05-21 09:25:25 | 2024-05-21 09:25:26 |
Judging History
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 n,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),i*(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(pair<d,int> p:v)
{
int j=abs(p.s); 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+1)*1./m-area(j,i));
else
smax(ans,cnt*1./m-area(j,i)),
smax(ans,(m-cnt+1)*1./m-area(i,j));
}
//corner piece: unique line
}
}
//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: 0ms
memory: 3804kb
input:
5 8 1 1 1 2 1 3 2 1 3 1 3 4 4 1 4 2
output:
result:
wrong output format Unexpected end of file - double expected