Submission #400931

# Submission time Handle Problem Language Result Execution time Memory
400931 2021-05-08T20:53:47 Z jenkinsser Planine (COCI21_planine) C++17
0 / 110
3 ms 892 KB
#include <bits/stdc++.h>
#define FOR(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define for0(ii,bb) FOR(ii,0,bb)
#define for1(ii,bb) FOR(ii,1,bb+1)
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define st first
#define nd second
#define pii pair<int,int>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define pdi pair<double,int>
#define vi vector<int>
#define sp " "
#define nl "\n"
#define all(x) x.begin(),x.end()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define int ll
 
using namespace std;
 
const int N = 1e5+5;
const int INF = 1e9+5;
const int mod = 998244353;
 
int n,h;
vector<pii> p;
 
bool ccw(pii x,pii y,pii z){
    return x.st*(y.nd-z.nd)+y.st*(z.nd-x.nd)+z.st*(x.nd-y.nd)>0;
}
 
bool cw(pii x,pii y,pii z){
    return x.st*(y.nd-z.nd)+y.st*(z.nd-x.nd)+z.st*(x.nd-y.nd)<0;
}
 
vector<pii> compute1(){
    vector<pii> hull;
    vector<pii> v;
    for(int i=2;i<n;i++){
        while(hull.size()>=2&&ccw(hull[(int)hull.size()-2],hull[(int)hull.size()-1],p[i]))
            hull.pop_back();
        hull.pb(p[i]);
        if(i&1){
            pii a=hull[(int)hull.size()-1];
            pii b=hull[(int)hull.size()-2];
            // cout << a.st << sp << a.nd << sp << b.st << sp << b.nd << sp;
            pii c={(a.st-b.st)*(h-b.nd)+b.st*(a.nd-b.nd),a.nd-b.nd};
            // cout << c.st << sp << c.nd << nl;
            v.pb(c);
        }
    }
    return v;
}
 
vector<pii> compute2(){
    vector<pii> hull;
    vector<pii> v;
    for(int i=2;i<n;i++){
        while(hull.size()>=2&&cw(hull[(int)hull.size()-2],hull[(int)hull.size()-1],p[i]))
            hull.pop_back();
        hull.pb(p[i]);
        if(i&1){
            pii a=hull[(int)hull.size()-1];
            pii b=hull[(int)hull.size()-2];
            // cout << a.st << sp << a.nd << sp << b.st << sp << b.nd << sp;
            pii c={(a.st-b.st)*(h-b.nd)+b.st*(a.nd-b.nd),a.nd-b.nd};
            // cout << c.st << sp << c.nd << nl;
            v.pb(c);
        }
    }
    return v;    
}
 
signed main(){
    fastio()
    cin >> n >> h;
    p.resize(n+2);
    for(int i=1;i<=n;i++)
        cin >> p[i].st >> p[i].nd;
    vector<pii> a=compute1();
    reverse(all(p));
    vector<pii> b=compute2();
    reverse(all(b));
    reverse(all(p));
    vector<pii> v;
    for(int i=0;i<(int)a.size();i++){
        v.pb({max((int)ceil((float)a[i].st/a[i].nd),0ll),min(b[i].st/b[i].nd,p[n].st)});
        // cout << (i+1)*2+1 << sp << max((int)ceil((float)a[i].st/a[i].nd),0ll) << sp << min(b[i].st/b[i].nd,p[n].st) << nl;
    }
    sort(all(v));
    int last=v[0].nd;
    int ans=1;
    for(int i=1;i<(int)v.size();i++){
        if(last<v[i].st){
            ans++;
            last=v[i].nd;
        }
    }
    cout << ans << nl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 892 KB Output isn't correct
2 Halted 0 ms 0 KB -