Submission #950318

# Submission time Handle Problem Language Result Execution time Memory
950318 2024-03-20T08:07:21 Z vjudge1 Planine (COCI21_planine) C++17
110 / 110
643 ms 69776 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define mp make_pair
#define ll long long
#define int ll
#define double long double
const ll INF=1e18,N=1e6+5;
bool cmp(pair<double,double> a, pair<double,double> b){
	if(a.fr==b.fr) return a.sc>b.sc;
	return a.fr<b.fr;
}
int x[N],y[N];
double slope(int a, int b){
	return (y[b]-y[a])/(x[b]-x[a]+0.0);
}
int cross(pair<int,int> a, pair<int,int> b){
	return a.fr*b.sc-a.sc*b.fr;
}
int cross(int a, int b, int c){
	return cross(mp(x[b]-x[a],y[b]-y[a]),mp(x[c]-x[a],y[c]-y[a]));
}
void solve(){
	int n,h;cin>>n>>h;
	for(int i=0;i<n;i++)
		cin>>x[i]>>y[i];
	vector<double> l(n),r(n);
	vector< pair<double,double> > v;
	deque<int> st;
	st.pb(0);
	for(int i=1;i<n;i++){
		while(st.size()>1 && cross(st[st.size()-2],st.back(),i)>0)
			st.pop_back();
		if(i%2==0){
			if(slope(i,st.back())==0) l[i]=-INF;
			else l[i]=x[st.back()]+(h-y[st.back()])/slope(i,st.back());
		}
		
		st.push_back(i);
	}
	while(!st.empty()) st.pop_back();
	st.pb(n-1);
	for(int i=n-2;i>=0;i--){
		while(st.size()>1 && cross(st[st.size()-2],st.back(),i)<0)
			st.pop_back();
		if(i%2==0){
			if(slope(st.back(),i)==0) r[i]=INF;
			else r[i]=x[i]+(h-y[i])/slope(st.back(),i);
		}
		st.push_back(i);
	}
	for(int i=2;i<n-1;i+=2) v.pb(mp(l[i],r[i]));
	sort(all(v),cmp);
	int ans=0;
	double rx=-INF;
	for(int i=0;i<v.size();i++){
		if(v[i].fr<=rx+1e-9){
			if(v[i].sc<=rx+1e-9)
				rx=v[i].sc;
		}
		else{
			ans++;
			rx=v[i].sc;
		}
	}
	//cout<<fixed<<setprecision(3);
	/*for(auto it: v)
		cout<<it.fr<<' '<<it.sc<<endl;*/
	cout<<ans;
}
main(){
	solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:61:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long double, long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
Main.cpp: At global scope:
Main.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3164 KB Output is correct
2 Correct 6 ms 3164 KB Output is correct
3 Correct 6 ms 3164 KB Output is correct
4 Correct 51 ms 12484 KB Output is correct
5 Correct 54 ms 12244 KB Output is correct
6 Correct 58 ms 12248 KB Output is correct
7 Correct 488 ms 68304 KB Output is correct
8 Correct 527 ms 69776 KB Output is correct
9 Correct 568 ms 68792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3164 KB Output is correct
2 Correct 6 ms 3164 KB Output is correct
3 Correct 6 ms 3164 KB Output is correct
4 Correct 51 ms 12484 KB Output is correct
5 Correct 54 ms 12244 KB Output is correct
6 Correct 58 ms 12248 KB Output is correct
7 Correct 488 ms 68304 KB Output is correct
8 Correct 527 ms 69776 KB Output is correct
9 Correct 568 ms 68792 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 509 ms 68812 KB Output is correct
18 Correct 496 ms 64412 KB Output is correct
19 Correct 51 ms 11976 KB Output is correct
20 Correct 514 ms 64716 KB Output is correct
21 Correct 50 ms 11980 KB Output is correct
22 Correct 562 ms 64696 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 560 ms 65468 KB Output is correct
25 Correct 63 ms 11972 KB Output is correct
26 Correct 643 ms 65848 KB Output is correct
27 Correct 26 ms 7392 KB Output is correct