Submission #79042

#TimeUsernameProblemLanguageResultExecution timeMemory
79042dualityTriangles (CEOI18_tri)C++11
100 / 100
50 ms3480 KiB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#include "trilib.h"

vi l,r,ll,rr;
int mysort(vi &v,int l,int r) {
    if (l >= r) return 0;
    int m = (l+r) / 2;
    int i = l,j = m+1,k = 0;
    vi temp(r-l+1);
    mysort(v,l,m),mysort(v,m+1,r);
    while (k < r-l+1) {
        if (i > m) temp[k++] = v[j++];
        else if (j > r) temp[k++] = v[i++];
        else if (is_clockwise(1,v[i]+1,v[j]+1)) temp[k++] = v[i++];
        else temp[k++] = v[j++];
    }
    for (i = l; i <= r; i++) v[i] = temp[i-l];
    return 0;
}
int main() {
    int i,j,n = get_n();
    for (i = 2; i < n; i++) {
        if (is_clockwise(1,2,i+1)) r.pb(i);
        else l.pb(i);
    }
    l.pb(1);
    mysort(l,0,(int) l.size()-1);
    mysort(r,0,(int) r.size()-1);
    ll.pb(0);
    for (i = 0; i < l.size(); i++) {
        while ((ll.size() >= 3) && !is_clockwise(ll[ll.size()-2]+1,ll.back()+1,l[i]+1)) ll.pop_back();
        ll.pb(l[i]);
    }
    ll.pb(0);
    rr.pb(0);
    for (i = 0; i < r.size(); i++) {
        while ((rr.size() >= 3) && !is_clockwise(rr[rr.size()-2]+1,rr.back()+1,r[i]+1)) rr.pop_back();
        rr.pb(r[i]);
    }
    rr.pb(0);
    reverse(rr.begin(),rr.end());
    if (rr.size() == 2) {
        give_answer(ll.size()-1);
        return 0;
    }
    int t = 0;
    if (is_clockwise(ll[1]+1,1,rr[1]+1)) {
        i = j = 1,t++;
        while (1) {
            if (is_clockwise(ll[i]+1,rr[j]+1,rr[j+1]+1)) t++,j++;
            else if (!is_clockwise(rr[j]+1,ll[i]+1,ll[i+1]+1)) t++,i++;
            else break;
        }
    }
    reverse(ll.begin(),ll.end());
    reverse(rr.begin(),rr.end());
    if (!is_clockwise(ll[1]+1,1,rr[1]+1)) {
        i = j = 1,t++;
        while (1) {
            if (!is_clockwise(ll[i]+1,rr[j]+1,rr[j+1]+1)) t++,j++;
            else if (is_clockwise(rr[j]+1,ll[i]+1,ll[i+1]+1)) t++,i++;
            else break;
        }
    }
    give_answer(ll.size()+rr.size()-t-2);

    return 0;
}

Compilation message (stderr)

tri.cpp: In function 'int main()':
tri.cpp:85:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < l.size(); i++) {
                 ~~^~~~~~~~~~
tri.cpp:91:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < r.size(); i++) {
                 ~~^~~~~~~~~~
#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...