답안 #447847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447847 2021-07-27T19:15:20 Z Jasiekstrz Planine (COCI21_planine) C++17
110 / 110
474 ms 61056 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e6;
struct Point
{
	long long x,y;
};
Point operator-(Point a,Point b)
{
	return {a.x-b.x,a.y-b.y};
}
long long operator*(Point a,Point b)
{
	return a.x*b.y-a.y*b.x;
}
struct Quo
{
	long long x,y;
	bool operator<(const Quo &oth) const
	{
		return (__int128)x*oth.y<(__int128)oth.x*y;
	}
	bool operator<=(const Quo &oth) const
	{
		return (__int128)x*oth.y<=(__int128)oth.x*y;
	}
};
Point tab[N+10];
pair<Quo,Quo> seg[N+10];
set<Quo> st;
vector<Point> stck;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,h;
	cin>>n>>h;
	for(int i=1;i<=n;i++)
		cin>>tab[i].x>>tab[i].y;
	int m=(n-2)/2;

	for(int i=2;i<n;i++)
	{
		if(i%2==0)
		{
			while(stck.size()>2)
			{
				auto tp=stck.back();
				stck.pop_back();
				if((tab[i]-stck.back())*(tp-stck.back())>0)
				{
					stck.push_back(tp);
					break;
				}
			}
			stck.push_back(tab[i]);
		}
		else
		{
			while(stck.size()>2)
			{
				auto tp=stck.back();
				stck.pop_back();
				if((tp-tab[i])*(stck.back()-tab[i])>0)
				{
					stck.push_back(tp);
					break;
				}
			}
			seg[i/2].fi=
			{tab[i].x*(stck.back().y-tab[i].y)+(stck.back().x-tab[i].x)*(h-tab[i].y),
				(stck.back().y-tab[i].y)};
		}
	}

	stck.clear();
	for(int i=n-1;i>1;i--)
	{
		if(i%2==0)
		{
			while(stck.size()>2)
			{
				auto tp=stck.back();
				stck.pop_back();
				if((tab[i]-stck.back())*(tp-stck.back())<0)
				{
					stck.push_back(tp);
					break;
				}
			}
			stck.push_back(tab[i]);
		}
		else
		{
			while(stck.size()>2)
			{
				auto tp=stck.back();
				stck.pop_back();
				if((tp-tab[i])*(stck.back()-tab[i])<0)
				{
					stck.push_back(tp);
					break;
				}
			}
			seg[i/2].se=
			{tab[i].x*(stck.back().y-tab[i].y)+(stck.back().x-tab[i].x)*(h-tab[i].y),
				(stck.back().y-tab[i].y)};
		}
	}

	//for(int i=3;i<n;i+=2)
	//{
	//	seg[i/2].fi=
	//	{(long long)tab[i].x*(tab[i-1].y-tab[i].y)+(long long)(tab[i-1].x-tab[i].x)*(h-tab[i].y),
	//		(tab[i-1].y-tab[i].y)};
	//	seg[i/2].se=
	//	{(long long)tab[i].x*(tab[i+1].y-tab[i].y)+(long long)(tab[i+1].x-tab[i].x)*(h-tab[i].y),
	//		(tab[i+1].y-tab[i].y)};	
	//}

	//for(int i=1;i<=m;i++)
	//	cerr<<seg[i].fi.x<<"/"<<seg[i].fi.y<<" "<<seg[i].se.x<<"/"<<seg[i].se.y<<"\n";
	pair<Quo,Quo> curr=seg[1];
	for(int i=2;i<=m;i++)
	{
		auto it=st.lower_bound(seg[i].fi);
		if(it!=st.end() && *it<=seg[i].se)
			continue;
		if(curr.se<seg[i].fi)
		{
			st.insert(curr.se);
			curr=seg[i];
		}
		else
		{
			curr.fi=max(curr.fi,seg[i].fi);
			curr.se=min(curr.se,seg[i].se);
		}
	}
	cout<<st.size()+1<<"\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 716 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 32 ms 4888 KB Output is correct
5 Correct 34 ms 5220 KB Output is correct
6 Correct 31 ms 4160 KB Output is correct
7 Correct 321 ms 37576 KB Output is correct
8 Correct 364 ms 41220 KB Output is correct
9 Correct 375 ms 37108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 716 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 32 ms 4888 KB Output is correct
5 Correct 34 ms 5220 KB Output is correct
6 Correct 31 ms 4160 KB Output is correct
7 Correct 321 ms 37576 KB Output is correct
8 Correct 364 ms 41220 KB Output is correct
9 Correct 375 ms 37108 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 333 ms 51292 KB Output is correct
18 Correct 399 ms 53108 KB Output is correct
19 Correct 33 ms 5580 KB Output is correct
20 Correct 333 ms 47492 KB Output is correct
21 Correct 30 ms 5060 KB Output is correct
22 Correct 474 ms 61056 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 391 ms 55620 KB Output is correct
25 Correct 32 ms 5796 KB Output is correct
26 Correct 249 ms 45740 KB Output is correct
27 Correct 15 ms 2880 KB Output is correct