Submission #516472

# Submission time Handle Problem Language Result Execution time Memory
516472 2022-01-21T11:27:38 Z KoD Geometrija (COCI21_geometrija) C++17
110 / 110
119 ms 8272 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

using i64 = std::int64_t;

struct Point {
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y) {}
    int belongs() const {
        if (x >= 0 and y >= 0) return 0;
        if (x < 0 and y > 0) return 0;
        return 1;
    }
    friend Point operator+(const Point& p, const Point& q) {
        return Point(p.x + q.x, p.y + q.y);
    }
    friend Point operator-(const Point& p, const Point& q) {
        return Point(p.x - q.x, p.y - q.y);
    }
    friend i64 cross(const Point& p, const Point& q) {
        return (i64)p.x * q.y - (i64)p.y * q.x;
    }
};

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;
    std::cin >> N;
    vector<Point> P(N);
    for (auto& [x, y] : P) {
        std::cin >> x >> y;
    }
    vector left(N, vector<int>(N));
    vector right(N, vector<int>(N));
    for (int pivot = 0; pivot < N; ++pivot) {
        vector<int> ord;
        ord.reserve(N - 1);
        for (int i = 0; i < N; ++i) {
            if (i != pivot) {
                ord.push_back(i);
                P[i] = P[i] - P[pivot];
            }
        }
        std::sort(ord.begin(), ord.end(), [&](const int i, const int j) {
            if (P[i].belongs() != P[j].belongs()) return P[i].belongs() < P[j].belongs();
            return cross(P[i], P[j]) > 0;
        });
        const auto get = [&](const int i) {
            return P[ord[i >= N - 1 ? i - (N - 1) : i]];
        };
        vector<int> half(2 * (N - 1));
        for (int i = 0, r = 0; i < N - 1; ++i) {
            while (r < i + N - 1 and cross(get(i), get(r)) >= 0) {
                r += 1;
            }
            half[i] = r;
            half[i + N - 1] = r + N - 1;
        }
        int sum_l = 0, sum_r = 0;
        for (int i = 0, r_l = 0, r_r = 0; i < N - 1; ++i) {
            while (r_l < half[i]) {
                sum_l += half[r_l];
                sum_r -= half[r_l];
                r_l += 1;
            }
            while (r_r < i + N - 1) {
                sum_r += half[r_r];
                r_r += 1;
            }
            const int above = half[i] - i;
            const int below = (N - 1) - above;
            left[pivot][ord[i]] = sum_l - above * half[i];
            right[pivot][ord[i]] = sum_r - below * (i + N);
            sum_l -= half[i];
        }
        for (const int i : ord) {
            P[i] = P[i] + P[pivot];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < i; ++j) {
            if (left[i][j] == right[j][i]) {
                ans += 1;
            }
        }
    }
    std::cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 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 308 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 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 308 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 4 ms 572 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 4 ms 556 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
19 Correct 4 ms 588 KB Output is correct
20 Correct 4 ms 568 KB Output is correct
21 Correct 4 ms 568 KB Output is correct
22 Correct 4 ms 588 KB Output is correct
23 Correct 4 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 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 308 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 4 ms 572 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 4 ms 556 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
19 Correct 4 ms 588 KB Output is correct
20 Correct 4 ms 568 KB Output is correct
21 Correct 4 ms 568 KB Output is correct
22 Correct 4 ms 588 KB Output is correct
23 Correct 4 ms 564 KB Output is correct
24 Correct 113 ms 8248 KB Output is correct
25 Correct 117 ms 8240 KB Output is correct
26 Correct 113 ms 8260 KB Output is correct
27 Correct 116 ms 8260 KB Output is correct
28 Correct 112 ms 8140 KB Output is correct
29 Correct 79 ms 5752 KB Output is correct
30 Correct 83 ms 6064 KB Output is correct
31 Correct 104 ms 8132 KB Output is correct
32 Correct 106 ms 8244 KB Output is correct
33 Correct 106 ms 8248 KB Output is correct
34 Correct 106 ms 8236 KB Output is correct
35 Correct 114 ms 8232 KB Output is correct
36 Correct 113 ms 8140 KB Output is correct
37 Correct 98 ms 8228 KB Output is correct
38 Correct 101 ms 8228 KB Output is correct
39 Correct 106 ms 8236 KB Output is correct
40 Correct 119 ms 8272 KB Output is correct
41 Correct 112 ms 8140 KB Output is correct
42 Correct 116 ms 8128 KB Output is correct