Submission #950315

# Submission time Handle Problem Language Result Execution time Memory
950315 2024-03-20T08:06:13 Z Baytoro Planine (COCI21_planine) C++17
110 / 110
566 ms 79288 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.sc==b.sc) return a.fr<b.fr;
	return a.sc<b.sc;
}
int x[N],y[N];
double slope(int a, int b){
	return (y[b]-y[a])/(x[b]-x[a]+0.0);
}

int cross(int A, int B, int C){
	pair<int,int> a=mp(x[A],y[A]);
	pair<int,int> b=mp(x[B],y[B]);
	pair<int,int> c=mp(x[C],y[C]);
	int tmp=a.fr*(b.sc-c.sc)+b.fr*(c.sc-a.sc)+c.fr*(a.sc-b.sc);
	if(tmp>0) return 0;
	if(tmp<0) return 1;
	return 2;
}

vector< pair<double,double> > v;
deque<int> st;
int n,h;
void add(int i, int x){
	while(st.size()>1 && cross(st[st.size()-2],st.back(),i)!=x)
			st.pop_back();
	st.pb(i);
}
double get(int i, int d){
	while(st.size()>1 && cross(st[st.size()-2],st.back(),i)!=d)
			st.pop_back();
	int X=x[st.back()],Y=y[st.back()];
	return (h-y[i])*1.0*(X-x[i])/(Y-y[i])+x[i];
}
void solve(){
	cin>>n>>h;
	for(int i=0;i<n;i++)
		cin>>x[i]>>y[i];
	vector<double> l(n),r(n);
	for(int i=n-2;i>=3;i-=2){
		add(i,0);
		l[i-1]=get(i-1,0);
	}
	while(!st.empty()) st.pop_back();
	for(int i=1;i<n-2;i+=2){
		add(i,1);
		r[i+1]=get(i+1,1);
	}
	for(int i=2;i<n-2;i+=2) v.pb(mp(l[i],r[i]));
	sort(all(v));
	int ans=0;
	double rx=-INF;
	for(int i=0;i<v.size();i++){
		if(v[i].sc>rx+1e-9){
			ans++;
			rx=v[i].fr;
		}
	}
	cout<<ans;
}
main(){
	solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:65: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]
   65 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
Main.cpp: At global scope:
Main.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   73 | 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 7 ms 3420 KB Output is correct
4 Correct 45 ms 12780 KB Output is correct
5 Correct 48 ms 12804 KB Output is correct
6 Correct 61 ms 13208 KB Output is correct
7 Correct 458 ms 70660 KB Output is correct
8 Correct 477 ms 72152 KB Output is correct
9 Correct 566 ms 72760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 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 2584 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2648 KB Output is correct
7 Correct 1 ms 2500 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 7 ms 3420 KB Output is correct
4 Correct 45 ms 12780 KB Output is correct
5 Correct 48 ms 12804 KB Output is correct
6 Correct 61 ms 13208 KB Output is correct
7 Correct 458 ms 70660 KB Output is correct
8 Correct 477 ms 72152 KB Output is correct
9 Correct 566 ms 72760 KB Output is correct
10 Correct 1 ms 2392 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 2584 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2648 KB Output is correct
16 Correct 1 ms 2500 KB Output is correct
17 Correct 448 ms 75884 KB Output is correct
18 Correct 456 ms 75040 KB Output is correct
19 Correct 46 ms 13000 KB Output is correct
20 Correct 437 ms 74156 KB Output is correct
21 Correct 45 ms 13064 KB Output is correct
22 Correct 504 ms 78072 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 478 ms 76972 KB Output is correct
25 Correct 45 ms 12996 KB Output is correct
26 Correct 555 ms 79288 KB Output is correct
27 Correct 23 ms 7892 KB Output is correct