답안 #447809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447809 2021-07-27T14:57:07 Z Jasiekstrz Planine (COCI21_planine) C++17
20 / 110
342 ms 33064 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 (__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;
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 588 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 30 ms 3956 KB Output is correct
5 Correct 33 ms 4104 KB Output is correct
6 Correct 29 ms 3164 KB Output is correct
7 Correct 288 ms 29604 KB Output is correct
8 Correct 341 ms 33064 KB Output is correct
9 Correct 342 ms 28920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 30 ms 3956 KB Output is correct
5 Correct 33 ms 4104 KB Output is correct
6 Correct 29 ms 3164 KB Output is correct
7 Correct 288 ms 29604 KB Output is correct
8 Correct 341 ms 33064 KB Output is correct
9 Correct 342 ms 28920 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Incorrect 1 ms 332 KB Output isn't correct
12 Halted 0 ms 0 KB -