제출 #816961

#제출 시각아이디문제언어결과실행 시간메모리
816961DJeniUpTriangles (CEOI18_tri)C++17
20 / 100
1 ms340 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;
}

vector<ll> S(ll l,ll r){
    vector<ll>k;
    k.clear();
    if(l==r){
        k.pb(l);
        return k;
    }
    ll m1=(l+r)/2;
    vector<ll>k1=S(l,m1);
    vector<ll>k2=S(m1+1,r);
    ll x=0;
    ll y=0;
    while(x<k1.size() || y<k2.size()){
        if(y==k2.size()){
            k.pb(k1[x]);
            x++;
        }else if(x==k1.size()){
            k.pb(k2[y]);
            y++;
        }else if(cl(1,k1[x],k2[y])==1){
            k.pb(k1[x]);
            x++;
        }else{
            k.pb(k2[y]);
            y++;
        }
    }
    return k;
}

int main(){
    n=get_n();
    if(n==3){
        give_answer(3);
        return 0;
    }
    vector<ll>k=S(2,n);
    for(auto it:k){
        v.pb(it);
    }
    a.pb(v[0]);
    a.pb(v[1]);
   // cout<<0<<" "<<v[0]<<endl;
    //cout<<1<<" "<<v[1]<<endl;
    ll x=2;
    for(int i=2;i<n-1;i++){
        //cout<<i<<" "<<v[i]<<endl;
        while(x>1 && cl(a[x-2],a[x-1],v[i])==0){
            x--;
            a.pop_back();
        }
        x++;
        a.pb(v[i]);
    }
    while(x>3 && (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
15 10
1 18
4 16
6 14
7 11
6 8
4 4
1 1

7
-640171411 -194312902
-841925336 987730324
190043513 -997888031
-818099011 526395621
765098899 -53534033
-519211010 -921903684
749848805 -765518967


*/

컴파일 시 표준 에러 (stderr) 메시지

tri.cpp: In function 'std::vector<int> S(ll, ll)':
tri.cpp:54:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     while(x<k1.size() || y<k2.size()){
      |           ~^~~~~~~~~~
tri.cpp:54:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     while(x<k1.size() || y<k2.size()){
      |                          ~^~~~~~~~~~
tri.cpp:55:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         if(y==k2.size()){
      |            ~^~~~~~~~~~~
tri.cpp:58:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         }else if(x==k1.size()){
      |                  ~^~~~~~~~~~~
#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...