답안 #447808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447808 2021-07-27T14:55:11 Z Jasiekstrz Planine (COCI21_planine) C++17
20 / 110
349 ms 45108 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e6;
struct Point
{
	int x,y;
};
struct Quo
{
	long long x,y;
	bool operator<(const Quo &oth) const
	{
		return x*oth.y<oth.x*y;
	}
	bool operator<=(const Quo &oth) const
	{
		return x*oth.y<=oth.x*y;
	}
};
Point tab[N+10];
pair<Quo,Quo> seg[N+10];
set<Quo> st;
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=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 700 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 716 KB Output is correct
4 Correct 30 ms 4908 KB Output is correct
5 Correct 40 ms 5332 KB Output is correct
6 Correct 29 ms 4540 KB Output is correct
7 Correct 298 ms 39564 KB Output is correct
8 Correct 349 ms 45108 KB Output is correct
9 Correct 329 ms 42844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 352 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 700 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 716 KB Output is correct
4 Correct 30 ms 4908 KB Output is correct
5 Correct 40 ms 5332 KB Output is correct
6 Correct 29 ms 4540 KB Output is correct
7 Correct 298 ms 39564 KB Output is correct
8 Correct 349 ms 45108 KB Output is correct
9 Correct 329 ms 42844 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Incorrect 1 ms 352 KB Output isn't correct
12 Halted 0 ms 0 KB -