Submission #950284

#TimeUsernameProblemLanguageResultExecution timeMemory
950284BaytoroPlanine (COCI21_planine)C++17
0 / 110
7 ms3160 KiB
#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 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; } 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)!=1) 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)); int ans=0; double rx=-INF; for(int i=0;i<v.size();i++){ if(rx+1e-9>=l[i]){ continue; } ans++; rx=r[i]; } //cout<<fixed<<setprecision(3); /*for(auto it: v) cout<<it.fr<<' '<<it.sc<<endl;*/ cout<<ans; } int main(){ solve(); }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:64:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long double, long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...