제출 #405506

#제출 시각아이디문제언어결과실행 시간메모리
405506ollelTriangles (CEOI18_tri)C++14
35 / 100
13 ms2452 KiB
#include <bits/stdc++.h> #include <iostream> #include "trilib.h" using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef tuple<int,int,int> tiii; #define rep(i,a,b) for(int i = a; i < b; i++) #define pb push_back int n, guesses = 999995; map<tiii, bool> cw; // bool is_clockwise(int a, int b, int c) { // cout << "clockwise? " << a << " " << b << " " << c << endl; // bool ans; // cin >> ans; // return ans; // } // // int get_n(){ // int N; cin >> N; return N; // } bool clockwise(int a, int b, int c){ tiii t = make_tuple(a, b, c); if (cw.find(t) != cw.end()) return cw[t]; guesses--; bool ans = is_clockwise(a, b, c); cw[{a, b, c}] = cw[{b, c, a}] = cw[{c, a, b}] = ans; cw[{a, c, b}] = cw[{c, b, a}] = cw[{b, a, c}] = !ans; return ans; } int getleft(int a, int b, set<int>& s) { for (auto & c : s) { if (c == b) continue; if (clockwise(a, b, c)) b = c; } return b; } int getright(int a, int b, set<int>& s) { for (auto & c : s) { if (c == b) continue; if (!clockwise(a, b, c)) b = c; } return b; } int first_hull() { int a = 1, b = 2; // assume a top set<int> left, right; rep(i, 3, n + 1) { if (clockwise(a, b, i)) left.insert(i); else right.insert(i); } if (left.empty() || right.empty()) return a; int l = getleft(a, b, left); int r = getright(a, b, right); if (clockwise(l, r, a)) return l; else return a; } vi sort_hull(int sortby) { vi s = {(sortby == 1) ? 2:1}; rep(i, 1, n + 1) { if (i == sortby || i == s[0]) continue; int low = 0, high = s.size(), mid; while (high - low > 1) { mid = (high + low) / 2; if (clockwise(sortby, i, s[mid])) high = mid; else low = mid; } if (clockwise(sortby, i, s[low])) s.insert(s.begin() + low, i); else s.insert(s.begin() + low + 1, i); } s.insert(s.begin(), sortby); return s; } int main() { n = get_n(); int sortby = first_hull(); vi s = sort_hull(sortby); int ans = n; vi nxt(n+1); rep(i,0,n-1) nxt[s[i]] = s[i + 1]; nxt[s[n - 1]] = s[0]; int cur = sortby, since = 0; while (since < 2*n) { since++; if (!clockwise(cur, nxt[cur], nxt[nxt[cur]])) { ans--; nxt[cur] = nxt[nxt[cur]]; since = 0; } cur = nxt[cur]; } cout << ans << endl; }
#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...