Submission #537635

# Submission time Handle Problem Language Result Execution time Memory
537635 2022-03-15T10:20:47 Z zaneyu Planine (COCI21_planine) C++14
110 / 110
364 ms 32804 KB
/*input

*/
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define MNTO(x,y) x=min(x,y)
#define MXTO(x,y) x=max(x,y)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define ld long double
#define sz(x) (int)x.size()
#define pii pair<ll,ll>
#define pdd pair<ld,ld>
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
const int INF=0x3f3f3f3f;
const int maxn=1e6+5;
ll triangle(pii o,pii a,pii b){
    if(o.f==-1e6-1) return a.s<=b.s;
    return (a.f-o.f)*(b.s-o.s)-(b.f-o.f)*(a.s-o.s);
}
bool cmp(pdd a,pdd b){
    return a.s<b.s;
}
const ld eps=1e-9;
pii arr[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,h;
    cin>>n>>h;
    vector<pdd> vv;
    REP(i,n) cin>>arr[i].f>>arr[i].s;
    vector<pii> v;
    v.pb({-1e6-1,h});
    REP1(i,n-2){
        while(sz(v)>=2 and triangle(v[sz(v)-2],v[sz(v)-1],arr[i])>0){
            v.pop_back();
        }
        if(i%2==0){
            vv.pb({0,0});
            ld m=1.0*(v.back().s-arr[i].s)/(v.back().f-arr[i].f);
            ld c=arr[i].s-m*arr[i].f;
            vv[sz(vv)-1].f=(h-c)/m;
        }
        v.pb(arr[i]);
    }
    REP(i,n) arr[i].f*=-1;
    v.clear();
    v.pb({-1e6-1,h});
    for(int i=n-2;i>=1;i--){
        while(sz(v)>=2 and triangle(v[sz(v)-2],v[sz(v)-1],arr[i])>0){
            v.pop_back();
        }
        if(i%2==0){
            ld m=1.0*(v.back().s-arr[i].s)/(v.back().f-arr[i].f);
            ld c=arr[i].s-m*arr[i].f;
            ld z=(h-c)/m;
            vv[i/2-1].s=-z;
        }
        v.pb(arr[i]);
    }
    sort(ALL(vv),cmp);
    ld cur=vv[0].s;
    int ans=1;
    for(auto x:vv){
        //cout<<x.s<<' '<<x.f<<'\n';
        if(x.f>cur+eps) ++ans,cur=x.s;
    }
    cout<<ans;
    
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 852 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 26 ms 4052 KB Output is correct
5 Correct 30 ms 4124 KB Output is correct
6 Correct 32 ms 4052 KB Output is correct
7 Correct 263 ms 32436 KB Output is correct
8 Correct 278 ms 32444 KB Output is correct
9 Correct 307 ms 32532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 852 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 26 ms 4052 KB Output is correct
5 Correct 30 ms 4124 KB Output is correct
6 Correct 32 ms 4052 KB Output is correct
7 Correct 263 ms 32436 KB Output is correct
8 Correct 278 ms 32444 KB Output is correct
9 Correct 307 ms 32532 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 302 ms 32624 KB Output is correct
18 Correct 286 ms 32772 KB Output is correct
19 Correct 34 ms 4048 KB Output is correct
20 Correct 281 ms 32516 KB Output is correct
21 Correct 30 ms 4068 KB Output is correct
22 Correct 289 ms 32804 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 283 ms 32632 KB Output is correct
25 Correct 29 ms 4048 KB Output is correct
26 Correct 364 ms 32660 KB Output is correct
27 Correct 13 ms 2252 KB Output is correct