답안 #407321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407321 2021-05-18T17:53:32 Z soroush Geometrija (COCI21_geometrija) C++17
110 / 110
577 ms 764 KB
#include <bits/stdc++.h>
using namespace std;
 
#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<
 
#define fi first
#define se second
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
int sign(ll x) {
    if (x > 0) return 1;
    if (x < 0) return -1;
    return 0;
}
 
int ccw(const pii& a, const pii& b, const pii& c) {
    return sign((ll)a.fi * (b.se - c.se) +
                (ll)b.fi * (c.se - a.se) +
                (ll)c.fi * (a.se - b.se));
}
 
 
bool intersect(const pii& a, const pii& b, const pii& c, const pii& d) {
    if (a == b || a == c || a == d || b == c || b == d || c == d) return false;
    return ccw(a, b, c) != ccw(a, b, d) && ccw(c, d, a) != ccw(c, d, b);
}
 
 
int n;
vector<pii> pts;
 
int ccw(int i, int j, int k) {
    return ccw(pts[i], pts[j], pts[k]);
}
 
bool intersect(int i, int j, int k, int l) {
    return intersect(pts[i], pts[j], pts[k], pts[l]);
}
 
 
int cmp_center;
bool cmp(int i, int j) {
    return ccw(cmp_center, i, j) == 1;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin >> n;
    pts.resize(n);
    for (auto& it : pts) cin >> it.fi >> it.se;
 
    vector<pii> edges;
    set<vi> triangles;
 
    sort(pts.begin(), pts.end());
    vector<bool> on_hull(n);
    int last = 0;
    do {
        on_hull[last] = true;
 
        int nxt = 0;
        if (last == 0) nxt = 1;
 
        for (int i = 0; i < n; i++)
            if (ccw(last, nxt, i) == 1)
                nxt = i;
 
        edges.push_back({last, nxt});
        if (last != 0 && nxt != 0)
            triangles.insert({0, nxt, last});
 
        last = nxt;
    } while (last != 0);
 
    for (int i = 0; i < n; i++) {
        if (on_hull[i]) continue;
 
        vi tr;
        for (auto& it : triangles)
            if (ccw(it[0], it[1], i) == 1 &&
                ccw(it[1], it[2], i) == 1 &&
                ccw(it[2], it[0], i) == 1) {
                tr = it;
                break;
            }
 
        assert(!tr.empty());
        triangles.erase(tr);
        triangles.insert({tr[0], tr[1], i});
        triangles.insert({tr[1], tr[2], i});
        triangles.insert({tr[2], tr[0], i});
 
        edges.push_back({i, tr[0]});
        edges.push_back({i, tr[1]});
        edges.push_back({i, tr[2]});
    }
 
    int sol = 0;
    for (auto& edg : edges) {
        int p = edg.fi, q = edg.se;
        vi a, b;
        for (int i = 0; i < n; i++) {
            if (ccw(p, q, i) == -1) a.push_back(i);
            if (ccw(p, q, i) == +1) b.push_back(i);
        }
 
        cmp_center = p;
        sort(a.begin(), a.end(), cmp);
        sort(b.begin(), b.end(), cmp);
 
        vi c = b;
        cmp_center = q;
        sort(c.begin(), c.end(), cmp);
        vi pos(n);
        for (int i = 0; i < (int)c.size(); i++) pos[c[i]] = i;
 
        bool ok = true;
        int j = 0, k = -1;
        for (int i = 0; i < (int)a.size(); i++) {
            while (j < (int)b.size() && ccw(a[i], p, b[j]) == -1) {
                k = max(k, pos[b[j]]);
                j++;
            }
 
            if (k != -1)
                ok &= !intersect(p, q, a[i], c[k]);
        }
 
        if (ok) sol++;
    }
 
    cout << sol << '\n';
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 300 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 300 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 16 ms 392 KB Output is correct
13 Correct 16 ms 396 KB Output is correct
14 Correct 13 ms 332 KB Output is correct
15 Correct 12 ms 368 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 13 ms 332 KB Output is correct
18 Correct 15 ms 332 KB Output is correct
19 Correct 15 ms 332 KB Output is correct
20 Correct 15 ms 384 KB Output is correct
21 Correct 17 ms 384 KB Output is correct
22 Correct 17 ms 392 KB Output is correct
23 Correct 15 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 300 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 16 ms 392 KB Output is correct
13 Correct 16 ms 396 KB Output is correct
14 Correct 13 ms 332 KB Output is correct
15 Correct 12 ms 368 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 13 ms 332 KB Output is correct
18 Correct 15 ms 332 KB Output is correct
19 Correct 15 ms 332 KB Output is correct
20 Correct 15 ms 384 KB Output is correct
21 Correct 17 ms 384 KB Output is correct
22 Correct 17 ms 392 KB Output is correct
23 Correct 15 ms 384 KB Output is correct
24 Correct 513 ms 696 KB Output is correct
25 Correct 503 ms 588 KB Output is correct
26 Correct 504 ms 588 KB Output is correct
27 Correct 505 ms 648 KB Output is correct
28 Correct 511 ms 640 KB Output is correct
29 Correct 339 ms 460 KB Output is correct
30 Correct 357 ms 708 KB Output is correct
31 Correct 110 ms 436 KB Output is correct
32 Correct 110 ms 460 KB Output is correct
33 Correct 311 ms 764 KB Output is correct
34 Correct 292 ms 460 KB Output is correct
35 Correct 445 ms 584 KB Output is correct
36 Correct 450 ms 512 KB Output is correct
37 Correct 484 ms 580 KB Output is correct
38 Correct 551 ms 572 KB Output is correct
39 Correct 455 ms 584 KB Output is correct
40 Correct 450 ms 680 KB Output is correct
41 Correct 577 ms 584 KB Output is correct
42 Correct 518 ms 584 KB Output is correct