QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#55017#4226. Cookie CutterKING_UTRE 2ms3772kbC++203.7kb2022-10-11 21:58:192022-10-11 21:58:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-11 21:58:21]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3772kb
  • [2022-10-11 21:58:19]
  • 提交

answer

#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loos")
#endif

#include <bits/stdc++.h>

using namespace std;

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
template<class t>using vc=vector<t>;
template<class t>using vvc=vc<vc<t>>;
template<class t, class u>bool chmin(t &a, u b){
	if(a > b){ a = b; return true;}
	else return false;
}
template<class t, class u>bool chmax(t &a, u b){
	if(a < b){ a = b; return true;}
	else return false;
}
using vi=vc<int>;
#define a first
#define b second
#define mp make_pair
using pi=pair<int,int>;

using ld=long double;
const ld eps=1e-9;
using pt=complex<ld>;
#define x real()
#define y imag()

ld dot(pt a,pt b){return a.x*b.x+a.y*b.y;}
int sgn(ld a){return a<-eps?-1:a>eps?1:0;}
int sgn(ld a,ld b){return sgn(a-b);}
ld crs(pt a,pt b){return a.x*b.y-a.y*b.x;}
ld crs(pt a,pt b,pt c){return crs(b-a,c-a);}
int ccw(pt a,pt b){return sgn(crs(a,b));}
int ccw(pt a,pt b,pt c){return ccw(b-a,c-a);}
int bet(pt a,pt b,pt c){
	pt d=b-a;
	ld e=dot(d,c-a);
	if(sgn(e)<=0)return sgn(e)-1;
	return sgn(e-norm(d))+1;
}

using ln=pair<pt,pt>;
pt dir(ln a){return a.b-a.a;}
pt eval(ln a,ld b){return a.a+dir(a)*b;}

pt cll(ln a,ln b){
	return eval(a,crs(b.a,b.b,a.a)/crs(dir(a),dir(b)));
}

template<class t> int lwb(const vc<t>&vs,t v){
	return lower_bound(all(vs),v)-vs.bg;
}

bool ptcmp(pt a,pt b){
	int s=sgn(a.x,b.x);
	if(s)return s<0;
	else return sgn(a.y,b.y)<0;
}

void slv(){
	ld side;cin>>side;
	int n;cin>>n;
	vc<pt> ps(n);
	
	vc<pt> rect{pt(0,0),pt(side,0),pt(side,side),pt(0,side)};
	vc<pt> work;
	auto getarea=[&](pt a,pt b){
		work.clear();
		rep(i,4){
			int j=(i+1)%4;
			if(ccw(a,b,rect[i])>=0){
				work.pb(rect[i]);
				if(ccw(a,b,rect[j])<0)
					work.pb(cll(ln(a,b),ln(rect[i],rect[j])));
			}else{
				if(ccw(a,b,rect[j])>=0)
					work.pb(cll(ln(a,b),ln(rect[i],rect[j])));
			}
		}
		ld sum=0;
		rep(i,si(work)){
			sum+=crs(work[i],work[(i+1)%si(work)]);
			//cerr<<i<<" "<<work[i].x<<" "<<work[i].y<<" "<<sum<<endl;
		}
		
		//cerr<<"{"<<a.x<<","<<a.y<<"},{"<<b.x<<","<<b.y<<"} "<<sum/2<<endl;
		
		return sum/2/(side*side);
	};
	
	rep(i,n){
		ld a,b;cin>>a>>b;
		ps[i]=pt(a,b);
	}
	sort(all(ps),ptcmp);
	
	ld ans=0;
	rep(i,n){
		pt a,b;
		if(ps[i].y*2<side){
			if(ps[i].x*2<side){
				a=pt(ps[i].x*2,0);
				b=pt(0,ps[i].y*2);
			}else{
				a=pt(side,ps[i].y*2);
				b=pt(ps[i].x*2-side,0);
			}
		}else{
			if(ps[i].x*2<side){
				a=pt(0,ps[i].y*2-side);
				b=pt(ps[i].x*2,side);
			}else{
				a=pt(ps[i].x*2-side,side);
				b=pt(side,ps[i].y*2-side);
			}
		}
		int cnt=0;
		rep(j,n)if(ccw(a,b,ps[j])>=0)cnt++;
		
		chmax(ans,ld(cnt)/n-getarea(a,b));
	}
	
	//cerr<<ans<<endl;
	
	vc<pi> qs;
	rep(i,n)rng(j,i+1,n){
		qs.eb(i,j);
	}
	auto Qcmp=[&](pi a,pi b){
		pt adir=ps[a.b]-ps[a.a];
		pt bdir=ps[b.b]-ps[b.a];
		int c=ccw(adir,bdir);
		if(c)return c>0;
		ld d=dot(ps[a.a],adir);
		ld e=dot(ps[b.a],adir);
		c=sgn(d,e);
		if(c)return c<0;
		d=dot(ps[a.b],adir);
		e=dot(ps[b.b],bdir);
		return sgn(d,e)<0;
	};
	
	vi idx(n);iota(all(idx),0);
	vi pos=idx;
	
	sort(all(qs),Qcmp);
	for(auto q:qs){
		pt a=ps[q.a];
		pt b=ps[q.b];
		int i=pos[q.a];
		int j=pos[q.b];
		
		assert(i+1==j);
		//cerr<<i<<" "<<j<<endl;
		//cerr<<"{"<<a.x<<","<<a.y<<"},{"<<b.x<<","<<b.y<<"}"<<" "<<i<<" "<<j<<endl;
		
		chmax(ans,ld(n-min(i,j))/n-getarea(a,b));
		chmax(ans,ld(max(i,j)+1)/n-getarea(b,a));
		
		swap(idx[i],idx[j]);
		swap(pos[idx[i]],pos[idx[j]]);
	}
	
	cout<<ans<<endl;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	slv();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3772kb

input:

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

output:

0.37500000000000000000

result:

ok found '0.3750000', expected '0.3750000', error '0.0000000'

Test #2:

score: -100
Dangerous Syscalls

input:

10000 2916
93 93
93 278
93 463
93 649
93 834
93 1019
93 1204
93 1389
93 1574
93 1760
93 1945
93 2130
93 2315
93 2500
93 2685
93 2871
93 3056
93 3241
93 3426
93 3611
93 3796
93 3982
93 4167
93 4352
93 4537
93 4722
93 4907
93 5093
93 5278
93 5463
93 5648
93 5833
93 6018
93 6204
93 6389
93 6574
93 6759...

output:


result: