Submission #263462

# Submission time Handle Problem Language Result Execution time Memory
263462 2020-08-13T17:23:17 Z TadijaSebez Demarcation (BOI14_demarcation) C++11
100 / 100
155 ms 22276 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
struct pt{
	ll x,y;
	pt(ll a=0,ll b=0):x(a),y(b){}
	bool operator == (pt b)const{return mp(x,y)==mp(b.x,b.y);}
	bool operator != (pt b)const{return mp(x,y)!=mp(b.x,b.y);}
	bool operator < (pt b)const{return mp(x,y)<mp(b.x,b.y);}
};
pt operator - (pt a,pt b){return pt(a.x-b.x,a.y-b.y);}
pt operator -= (pt&a,pt b){return a=a-b;}
pt operator + (pt a,pt b){return pt(a.x+b.x,a.y+b.y);}
pt operator += (pt&a,pt b){return a=a+b;}
bool eq(vector<pt> a,vector<pt> b){
	if(a.size()!=b.size())return 0;
	for(int i=0;i<a.size();i++)if(a[i]!=b[i])return 0;
	return 1;
}
void norm(vector<pt>&a){
	int mn=0;
	for(int i=0;i<a.size();i++)if(a[i]<a[mn])mn=i;
	vector<pt> tmp;
	for(int i=0;i<a.size();i++)tmp.pb(a[(mn+i)%a.size()]);
	a=tmp;
	if(a[1].x==a[0].x)reverse(a.begin()+1,a.end());
	for(int i=1;i<a.size();i++)a[i]-=a[0];
	a[0]=pt(0,0);
}
void rotate(vector<pt>&a){
	for(pt&p:a)p=pt(-p.y,p.x);
}
void mirror(vector<pt>&a){
	for(pt&p:a)p=pt(-p.x,p.y);
}
bool on_line(pt a,pt b,pt c){
	return (a.x==b.x&&a.x==c.x)||(a.y==b.y&&a.y==c.y);
}
void pop(vector<pt>&a){
	while(a.size()>3&&on_line(a.back(),a[0],a[1]))a.erase(a.begin());
	while(a.size()>3&&on_line(a[0],a.back(),a[(int)a.size()-2]))a.pop_back();
	while(a.size()>3&&on_line(a[(int)a.size()-3],a[(int)a.size()-2],a.back()))a.erase(a.end()-2);
}
pt min_pt(vector<pt> a){
	pt ans=a[0];
	for(pt p:a)ans=min(ans,p);
	return ans;
}
bool Check(vector<pt> a,vector<pt> b){
	if(a.size()!=b.size())return 0;
	norm(a);
	for(int i=0;i<2;i++){
		for(int j=0;j<4;j++){
			norm(b);
			if(eq(a,b))return 1;
			rotate(b);
		}
		mirror(b);
	}
	return 0;
}
struct seg{
	pt a,b;
	seg(){}
	seg(pt x,pt y):a(x),b(y){}
	int type(){
		if(a.y==b.y)return a.x<b.x?-1:1;
		if(a.x==b.x)return a.y<b.y?2:3;
	}
	ll get(){
		return a.y*(a.x-b.x);
	}
	ll X(){return (a.x+b.x)/2;}
};
const int N=200050;
seg s[N];
ll sum[N],tme[N];
bool Solve(vector<pt> a,seg&ans){
	vector<pii> evs;
	for(int i=0;i<a.size();i++){
		int j=(i+1)%a.size();
		s[i+1]=seg(a[i],a[j]);
		evs.pb({min(a[i].y,a[j].y),-i-1});
		evs.pb({max(a[i].y,a[j].y),i+1});
	}
	for(int i=1;i<=a.size();i++)sum[i]=sum[i-1]+s[i].get();
	ll area=sum[a.size()];
	auto cmp=[&](int a,int b){return s[a].X()<s[b].X();};
	set<int,decltype(cmp)> all(cmp);
	auto cons=[&](int j,int i,ll tr,seg&ans){
		ll tl=tme[j];
		if(tl>tr)return 0;
		if(s[i].type()!=2||s[j].type()!=3)return 0;
		ll A=sum[j]+(j<i?sum[a.size()]-sum[i-1]:-sum[i-1]);
		ll dif=A-area/2;
		ll rng=s[i].a.x-s[j].a.x;
		if(dif%rng!=0)return 0;
		ll H=dif/rng;
		if(H&1)return 0;
		if(H>=tl&&H<=tr){
			pt o1(s[i].a.x,H),o2(s[j].a.x,H);
			vector<pt> p1,p2;
			for(int i1=i;i1!=j;i1=i1==a.size()?1:i1+1){
				p1.pb(s[i1].b);
			}
			if(p1.back()!=o2)p1.pb(o2);
			if(p1.front()!=o1)p1.pb(o1);
			for(int i2=j;i2!=i;i2=i2==a.size()?1:i2+1){
				p2.pb(s[i2].b);
			}
			if(p2.back()!=o1)p2.pb(o1);
			if(p2.front()!=o2)p2.pb(o2);
			pop(p1);pop(p2);
			if(Check(p1,p2)){
				ans=seg(o1,o2);
				return 1;
			}
		}
		return 0;
	};
	sort(evs.begin(),evs.end());
	for(auto e:evs){
		ll t=e.first;
		int i=abs(e.second);
		if(e.second<0){
			all.insert(i);
			auto it=all.find(i);
			if(it!=all.begin()&&next(it)!=all.end()){
				if(cons(*prev(it),*next(it),t-2,ans))
					return 1;
			}
			if(it!=all.begin()){
				tme[*prev(it)]=t;
			}
			if(next(it)!=all.end()){
				tme[i]=t;
			}
		}else{
			auto it=all.find(i);
			if(it!=all.begin()){
				if(cons(*prev(it),*it,t,ans))
					return 1;
			}
			if(next(it)!=all.end()){
				if(cons(*it,*next(it),t,ans))
					return 1;
			}
			if(it!=all.begin()&&next(it)!=all.end()){
				tme[*prev(it)]=t+2;
			}
			all.erase(it);
		}
	}
	return 0;
}
int main(){
	int n;
	scanf("%i",&n);
	vector<pt> a(n);
	for(pt&p:a)scanf("%lld %lld",&p.x,&p.y),p.x*=2,p.y*=2;
	pt add=min_pt(a);
	seg ans;
	norm(a);
	if(Solve(a,ans)){
		ans.a+=add;
		ans.b+=add;
		printf("%lld %lld %lld %lld\n",ans.a.x/2,ans.a.y/2,ans.b.x/2,ans.b.y/2);
		return 0;
	}
	rotate(a);
	pt add2=min_pt(a);
	norm(a);
	if(Solve(a,ans)){
		ans.a+=add2;
		ans.b+=add2;
		vector<pt> sol={ans.a,ans.b};
		for(int i=0;i<3;i++)rotate(sol);
		sol[0]+=add;
		sol[1]+=add;
		printf("%lld %lld %lld %lld\n",sol[0].x/2,sol[0].y/2,sol[1].x/2,sol[1].y/2);
		return 0;
	}
	printf("NO\n");
	return 0;
}

Compilation message

demarcation.cpp: In function 'bool eq(std::vector<pt>, std::vector<pt>)':
demarcation.cpp:20:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=0;i<a.size();i++)if(a[i]!=b[i])return 0;
      |              ~^~~~~~~~~
demarcation.cpp: In function 'void norm(std::vector<pt>&)':
demarcation.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for(int i=0;i<a.size();i++)if(a[i]<a[mn])mn=i;
      |              ~^~~~~~~~~
demarcation.cpp:27:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i=0;i<a.size();i++)tmp.pb(a[(mn+i)%a.size()]);
      |              ~^~~~~~~~~
demarcation.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for(int i=1;i<a.size();i++)a[i]-=a[0];
      |              ~^~~~~~~~~
demarcation.cpp: In function 'bool Solve(std::vector<pt>, seg&)':
demarcation.cpp:83:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |  for(int i=0;i<a.size();i++){
      |              ~^~~~~~~~~
demarcation.cpp:89:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  for(int i=1;i<=a.size();i++)sum[i]=sum[i-1]+s[i].get();
      |              ~^~~~~~~~~~
demarcation.cpp: In lambda function:
demarcation.cpp:106:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |    for(int i1=i;i1!=j;i1=i1==a.size()?1:i1+1){
      |                          ~~^~~~~~~~~~
demarcation.cpp:111:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |    for(int i2=j;i2!=i;i2=i2==a.size()?1:i2+1){
      |                          ~~^~~~~~~~~~
demarcation.cpp: In member function 'int seg::type()':
demarcation.cpp:72:2: warning: control reaches end of non-void function [-Wreturn-type]
   72 |  }
      |  ^
demarcation.cpp: In function 'int main()':
demarcation.cpp:161:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  161 |  scanf("%i",&n);
      |  ~~~~~^~~~~~~~~
demarcation.cpp:163:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  163 |  for(pt&p:a)scanf("%lld %lld",&p.x,&p.y),p.x*=2,p.y*=2;
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8096 KB Output is correct
2 Correct 4 ms 6656 KB Output is correct
3 Correct 5 ms 6528 KB Output is correct
4 Correct 11 ms 7880 KB Output is correct
5 Correct 4 ms 6656 KB Output is correct
6 Correct 4 ms 6528 KB Output is correct
7 Correct 4 ms 6528 KB Output is correct
8 Correct 4 ms 6656 KB Output is correct
9 Correct 128 ms 19568 KB Output is correct
10 Correct 4 ms 6656 KB Output is correct
11 Correct 4 ms 6656 KB Output is correct
12 Correct 4 ms 6656 KB Output is correct
13 Correct 5 ms 6528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6656 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Correct 4 ms 6528 KB Output is correct
4 Correct 4 ms 6528 KB Output is correct
5 Correct 4 ms 6528 KB Output is correct
6 Correct 4 ms 6656 KB Output is correct
7 Correct 5 ms 6528 KB Output is correct
8 Correct 3 ms 6528 KB Output is correct
9 Correct 5 ms 6656 KB Output is correct
10 Correct 4 ms 6528 KB Output is correct
11 Correct 4 ms 6656 KB Output is correct
12 Correct 4 ms 6656 KB Output is correct
13 Correct 4 ms 6656 KB Output is correct
14 Correct 4 ms 6528 KB Output is correct
15 Correct 4 ms 6528 KB Output is correct
16 Correct 4 ms 6656 KB Output is correct
17 Correct 4 ms 6656 KB Output is correct
18 Correct 5 ms 6656 KB Output is correct
19 Correct 5 ms 6656 KB Output is correct
20 Correct 5 ms 6656 KB Output is correct
21 Correct 4 ms 6656 KB Output is correct
22 Correct 4 ms 6656 KB Output is correct
23 Correct 4 ms 6656 KB Output is correct
24 Correct 5 ms 6528 KB Output is correct
25 Correct 4 ms 6528 KB Output is correct
26 Correct 4 ms 6528 KB Output is correct
27 Correct 4 ms 6528 KB Output is correct
28 Correct 5 ms 6656 KB Output is correct
29 Correct 4 ms 6584 KB Output is correct
30 Correct 4 ms 6528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6528 KB Output is correct
2 Correct 4 ms 6528 KB Output is correct
3 Correct 4 ms 6528 KB Output is correct
4 Correct 4 ms 6528 KB Output is correct
5 Correct 4 ms 6528 KB Output is correct
6 Correct 4 ms 6528 KB Output is correct
7 Correct 4 ms 6656 KB Output is correct
8 Correct 4 ms 6656 KB Output is correct
9 Correct 4 ms 6528 KB Output is correct
10 Correct 4 ms 6528 KB Output is correct
11 Correct 5 ms 6656 KB Output is correct
12 Correct 4 ms 6528 KB Output is correct
13 Correct 4 ms 6656 KB Output is correct
14 Correct 4 ms 6656 KB Output is correct
15 Correct 5 ms 6656 KB Output is correct
16 Correct 4 ms 6528 KB Output is correct
17 Correct 4 ms 6656 KB Output is correct
18 Correct 5 ms 6636 KB Output is correct
19 Correct 4 ms 6656 KB Output is correct
20 Correct 4 ms 6656 KB Output is correct
21 Correct 4 ms 6656 KB Output is correct
22 Correct 4 ms 6656 KB Output is correct
23 Correct 4 ms 6528 KB Output is correct
24 Correct 4 ms 6528 KB Output is correct
25 Correct 4 ms 6528 KB Output is correct
26 Correct 4 ms 6528 KB Output is correct
27 Correct 5 ms 6528 KB Output is correct
28 Correct 4 ms 6656 KB Output is correct
29 Correct 5 ms 6528 KB Output is correct
30 Correct 4 ms 6528 KB Output is correct
31 Correct 4 ms 6656 KB Output is correct
32 Correct 5 ms 6784 KB Output is correct
33 Correct 5 ms 6784 KB Output is correct
34 Correct 6 ms 6784 KB Output is correct
35 Correct 5 ms 6784 KB Output is correct
36 Correct 5 ms 6784 KB Output is correct
37 Correct 6 ms 6784 KB Output is correct
38 Correct 6 ms 6784 KB Output is correct
39 Correct 5 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 8096 KB Output is correct
2 Correct 5 ms 6656 KB Output is correct
3 Correct 4 ms 6528 KB Output is correct
4 Correct 10 ms 7888 KB Output is correct
5 Correct 4 ms 6528 KB Output is correct
6 Correct 4 ms 6528 KB Output is correct
7 Correct 4 ms 6656 KB Output is correct
8 Correct 4 ms 6528 KB Output is correct
9 Correct 114 ms 19564 KB Output is correct
10 Correct 4 ms 6656 KB Output is correct
11 Correct 4 ms 6656 KB Output is correct
12 Correct 4 ms 6528 KB Output is correct
13 Correct 4 ms 6528 KB Output is correct
14 Correct 4 ms 6656 KB Output is correct
15 Correct 4 ms 6656 KB Output is correct
16 Correct 4 ms 6656 KB Output is correct
17 Correct 4 ms 6656 KB Output is correct
18 Correct 4 ms 6528 KB Output is correct
19 Correct 4 ms 6528 KB Output is correct
20 Correct 4 ms 6528 KB Output is correct
21 Correct 4 ms 6656 KB Output is correct
22 Correct 4 ms 6656 KB Output is correct
23 Correct 4 ms 6528 KB Output is correct
24 Correct 5 ms 6656 KB Output is correct
25 Correct 5 ms 6656 KB Output is correct
26 Correct 4 ms 6656 KB Output is correct
27 Correct 4 ms 6528 KB Output is correct
28 Correct 4 ms 6528 KB Output is correct
29 Correct 4 ms 6528 KB Output is correct
30 Correct 4 ms 6528 KB Output is correct
31 Correct 5 ms 6528 KB Output is correct
32 Correct 4 ms 6528 KB Output is correct
33 Correct 4 ms 6528 KB Output is correct
34 Correct 4 ms 6656 KB Output is correct
35 Correct 6 ms 6784 KB Output is correct
36 Correct 5 ms 6784 KB Output is correct
37 Correct 6 ms 6784 KB Output is correct
38 Correct 6 ms 6784 KB Output is correct
39 Correct 5 ms 6784 KB Output is correct
40 Correct 5 ms 6784 KB Output is correct
41 Correct 6 ms 6784 KB Output is correct
42 Correct 5 ms 6656 KB Output is correct
43 Correct 8 ms 6904 KB Output is correct
44 Correct 39 ms 12688 KB Output is correct
45 Correct 41 ms 13044 KB Output is correct
46 Correct 29 ms 10992 KB Output is correct
47 Correct 28 ms 8584 KB Output is correct
48 Correct 37 ms 10088 KB Output is correct
49 Correct 65 ms 18496 KB Output is correct
50 Correct 106 ms 17628 KB Output is correct
51 Correct 152 ms 19812 KB Output is correct
52 Correct 121 ms 22276 KB Output is correct
53 Correct 155 ms 16016 KB Output is correct
54 Correct 70 ms 17732 KB Output is correct
55 Correct 30 ms 11536 KB Output is correct
56 Correct 122 ms 19308 KB Output is correct
57 Correct 142 ms 16824 KB Output is correct
58 Correct 144 ms 17772 KB Output is correct
59 Correct 64 ms 19136 KB Output is correct
60 Correct 57 ms 10788 KB Output is correct
61 Correct 25 ms 8632 KB Output is correct
62 Correct 37 ms 10024 KB Output is correct
63 Correct 60 ms 11532 KB Output is correct
64 Correct 53 ms 11552 KB Output is correct
65 Correct 67 ms 10440 KB Output is correct
66 Correct 87 ms 14928 KB Output is correct