제출 #78437

#제출 시각아이디문제언어결과실행 시간메모리
78437SaboonTriangles (CEOI18_tri)C++14
55 / 100
528 ms2896 KiB
#include <iostream>
#include <queue>
#include <bitset>
#include <stack>
#include <vector>
#include <trilib.h>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#define prime first
#define alpha second
#define PB push_back
#define PF push_front
#define MP make_pair

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef unsigned long long ull;

const int maxn = 1e5 + 100;

int first = 1;
/*
int get_n () {
    int k;
    cin >> k;
    return k;
}

bool is_clockwise (int fi, int se, int th) {
    cout << fi << " " << se << " " << th << endl;
    bool k;
    cin >> k;
    return k;
}

void give_answer (int x) {
    cout << x << endl;
}
*/
int pre[maxn], nex[maxn];

void remove (int fi, int mid, int se) {
    pre[se] = fi;
    nex[fi] = se;
    first = fi;
}

void insert (int fi, int mid, int se) {
    nex[fi] = mid;
    nex[mid] = se;
    pre[se] = mid;
    pre[mid] = fi;
}

int main() {
    ios::sync_with_stdio(false);
    int n = get_n ();
    if (is_clockwise (1, 2, 3)) {
        nex[1] = 2;
        nex[2] = 3;
        nex[3] = 1;
        pre[1] = 3;
        pre[2] = 1;
        pre[3] = 2;
    }
    else {
        nex[1] = 3;
        nex[3] = 2;
        nex[2] = 1;
        pre[1] = 2;
        pre[2] = 3;
        pre[3] = 1;
    }
    for (int i = 4; i <= n; i++) {
        int st = first, found = 0;
        while (true) {
            if (!is_clockwise (st, nex[st], i)) {
                insert (st, i, nex[st]);
                found = 1;
                break;
            }
            st = nex[st];
            if (st == first)
                break;
        }
        if (!found)
            continue;
        while (!is_clockwise (i, nex[i], nex[nex[i]]))
            remove (i, nex[i], nex[nex[i]]);
        while (!is_clockwise (pre[pre[i]], pre[i], i))
            remove (pre[pre[i]], pre[i], i);
    }
    int cnt = 0, st = first;
    while (true) {
        cnt ++;
        st = nex[st];
        if (st == first)
            break;
    }
    give_answer (cnt);
}
#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...