제출 #681131

#제출 시각아이디문제언어결과실행 시간메모리
681131sysiaTriangles (CEOI18_tri)C++17
20 / 100
1 ms340 KiB
//Sylwia Sapkowska #include <bits/stdc++.h> #include "trilib.h" #pragma GCC optimize("O3", "unroll-loops") using namespace std; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long typedef pair<int, int> T; const int oo = 1e18, oo2 = 1e9+7, K = 30; const int mod = 998244353; /* Solution: Creating convex hull requires 3 steps: a) finding a point which lies on convex hull - ?? queries b) angular sort with respect to the point from a) - O(n log n) queries c) finding actual convex hull - O(n) queries --At most one point not on the convex hull -> if we choose two different points, then one of them certainly lies on the convex hull. --Let's sort points with respect to some random point. Then this point lies on the convex hull iff first or last point of the sorted list creates a side with that random point (we can check how many points lie on which side of that line). */ mt19937 rng(chrono::steady_clock().now().time_since_epoch().count()); int p(int a, int b){return a+rng()%(b-a+1);} int cw(int a, int b, int c){ if (a == b || b == c || a == c) return 0; return is_clockwise(a, b, c) ? 1 : -1; } void solve(){ int n = get_n(); auto solve = [&](int v){ vector<int>ord(n); // cout << v << "\n"; iota(ord.begin(), ord.end(), 1); ord.erase(ord.begin()+v-1); stable_sort(ord.begin(), ord.end(), [&](auto x, auto y){return cw(v, x, y) == 1;}); // for (auto x: ord) cout << x << " "; // cout << "\n"; auto check = [&](int a, int b){ int x = 0, y = 0; for (int i = 1; i<=n; i++){ int u = cw(a, b, i); if (u == -1) x++; else if (u == 1) y++; } if (x > 0 && y > 0) return false; return true; }; if (check(v, ord[0])){ // cout << "found\n"; vector<int>hull; hull.emplace_back(v); for (auto x: ord){ if (x == v) continue; while (hull.size() >= 2 && cw(hull.end()[-2], hull.end()[-1], x) == -1) hull.pop_back(); hull.emplace_back(x); } // for (auto x: hull) cout << x << " "; // cout << "\n; give_answer((int)hull.size()); exit(0); } return ord[0]; }; int v = solve(p(1, n)); int u = solve(v); //use second algorithm -- upper and lower hull with respect to the line {v, ord[0]} vector<int>lower, upper; for (int i = 1; i<=n; i++){ if (i == v || i == u) continue; if (cw(v, u, i) == 1) lower.emplace_back(i); else upper.emplace_back(i); } lower.emplace_back(u); upper.emplace_back(u); stable_sort(lower.begin(), lower.end(), [&](auto x, auto y){return cw(v, x, y) == 1;}); stable_sort(upper.begin(), upper.end(), [&](auto x, auto y){return cw(v, x, y) == 1;}); // reverse(upper.begin(), upper.end()); // for (auto x: lower) cout << x << " "; // cout << "\n"; // for (auto x: upper) cout << x << " "; // cout << "\n"; int ans = 0; for (vector<int> curr: {lower, upper}){ vector<int>hull = {v}; for (auto x: curr){ while ((int)hull.size() >= 2 && cw(hull.end()[-2], hull.end()[-1], x) == -1) hull.pop_back(); hull.emplace_back(x); } // for (auto x: hull) cout << x << " "; // cout << "\n"; ans += (int)hull.size()-2; } // cout << ans << "\n"; give_answer(ans); } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) solve(); return 0; }
#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...