Submission #813367

#TimeUsernameProblemLanguageResultExecution timeMemory
813367DJeniUpTriangles (CEOI18_tri)C++17
0 / 100
1 ms468 KiB
#include "trilib.h"
#include "bits/stdc++.h"

using namespace std;

typedef int ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef pair<ll,ull>pairull;
typedef pair<ll,pairll>pair3l;
typedef long double ld;
typedef pair<ld,ld>pairld;

typedef pair<string,ll>pairsl;

#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define N 100007
#define MOD 1000000007
#define INF 10000000000007
#define eps 0.00000000001
#define A 50
#define PI 3.14159265359

ll n,d[40007],mn,mx;

deque<ll>v,a;

vector<ll>h;

map<pair3l,ll>m;

ll cl(ll x,ll y,ll z){
    if(m[{x,{y,z}}]==0){
        m[{x,{y,z}}]=ll(is_clockwise(x,y,z))+1;
    }
    return m[{x,{y,z}}]-1;
}

int main(){
    n=get_n();
    if(n==3){
        give_answer(3);
        return 0;
    }
    v.pb(2);
    for(int i=3;i<=n;i++){
        ll l=0;
        ll r=v.size()-1;
        while(l<r){
            ll m1=(l+r)/2;
            if(cl(1,i,v[m1])==1){
                r=m1;
            }else l=m1+1;
        }
        for(int j=1;i<=l;j++){
            v.pb(v.front());
            v.pop_front();
        }
        v.push_front(i);
    }
    a.pb(v[0]);
    a.pb(v[1]);
    ll x=2;
    for(int i=2;i<n-1;i++){
        while(x>1 && cl(a[x-2],a[x-1],v[i])==0){
            x--;
            a.pop_back();
        }
        x++;
        a.pb(v[i]);
    }
    while(cl(a[x-1],a[0],a[1])==0 || cl(a[x-2],a[x-1],a[0])==0){
        if(cl(a[x-1],a[0],a[1])==0){
            x--;
            a.pop_front();
        }else{
            x--;
            a.pop_back();
        }
    }
    ll y=0;
    for(int i=0;i<x;i++){
        if(cl(a[i],1,a[(i+1)%x])==1)y++;
    }
    if(y>0){
        give_answer(x-y+2);
    }else give_answer(x);
    return 0;
}

/*
8
1 1
1 18
4 16
6 14
7 11
6 8
4 4
15 10


*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...