Submission #446221

#TimeUsernameProblemLanguageResultExecution timeMemory
446221prvocisloFence (CEOI08_fence)C++17
30 / 100
1 ms332 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int stlp = 20, strom = 111; void upd(int &a, const int &b) { a = min(a, b); } struct bod { int x, y; }; int sign(int a) { return (a == 0 ? 0 : (a < 0 ? -1 : 1)); } int area(bod a, bod b, bod c) // orientovany obsah uhlu <) abc { a.x -= b.x, a.y -= b.y; c.x -= b.x, c.y -= b.y; return a.x * c.y - a.y * c.x; } bool inside_tri(const bod &a, const bod &b, const bod &c, const bod &i) { int zab = sign(area(a, b, i)), zbc = sign(area(b, c, i)), zca = sign(area(c, a, i)); return zab == zca && zca == zbc; } bool inside(const bod &a, const bod &b, const bod &c, const vector<bod> &v) { for (const bod &i : v) if (inside_tri(a, b, c, i)) return true; return false; } bod o; bool cmp(const bod &a, const bod &b) { return area(a, o, b) < 0; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<bod> f(n), s(m); int ans = m * strom, id = 0; for (int i = 0; i < n; i++) { cin >> f[i].x >> f[i].y; if (f[i].x < f[id].x || (f[i].x == f[id].x && f[i].y < f[id].y)) id = i; } o = f[id]; swap(f[id], f[0]); sort(f.begin(), f.end(), cmp); vector<bod> ko; for (int i = 0; i < n; i++) { if (ko.size() >= 2 && area(ko[ko.size()-1], ko[ko.size()-2], f[i]) > 0) ko.pop_back(); ko.push_back(f[i]); } int k = ko.size(); for (int i = 0; i < k; i++) ko.push_back(ko[i]); int inside_ko = 0; for (int i = 0; i < m; i++) { cin >> s[i].x >> s[i].y; bool is_in = false; for (int j = 2; j < k; j++) is_in |= inside_tri(ko[0], ko[j-1], ko[j], s[i]); inside_ko += is_in; } vector<vector<bool> > ok(2*k, vector<bool>(2*k)); for (int i = 0; i < 2*k-1; i++) { ok[i][i] = ok[i][i+1] = true; for (int j = i+2; j < min(i+k, 2*k); j++) if (ok[i][j-1] && !inside(ko[i], ko[j-1], ko[j], s)) ok[i][j] = true; } vector<vector<int> > dp(2*k, vector<int>(2*k, k+1)); for (int i = 0; i < k; i++) { dp[i][i] = 0; for (int r1 = i; r1 < i + k; r1++) for (int r2 = r1+1; r2 <= i+k; r2++) if (ok[r1][r2]) upd(dp[i][r2], dp[i][r1] + 1); upd(ans, dp[i][i+k]*stlp + (m - inside_ko)*strom); } cout << ans << "\n"; 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...
#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...