답안 #518247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518247 2022-01-23T09:06:05 Z Vimmer Geometrija (COCI21_geometrija) C++14
50 / 110
1000 ms 19732 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")

#define F first
#define S second
#define PB push_back
#define M ll(1e9 + 7)
#define sz(x) int(x.size())
#define N 1001
#define pri(x) cout << x << endl
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

using namespace std;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;

const ld eps = 1e-10;

pair <ld, ld> convert(int x1, int y1, int x2, int y2)
{
    ld k = 0;

    if (x2 != x1)
        k = ld(y2 - y1) / ld(x2 - x1);

    ld b = ld(y1) - k * x1;

    return {k, b};
}

pair <ld, ld> inter(pair <ld, ld> x, pair <ld, ld> y)
{
    if (fabs(x.F - y.F) < eps)
        return {1e18, 1e18};

    ld X = (y.S - x.S) / (x.F - y.F);

    ld Y = (x.F * X + x.S);

    return {X, Y};
}

pair <ld, ld> otr[N][N];

int main()
{
    istream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//    freopen("1.in", "r", stdin);

    int n;

    cin >> n;

    int x[n], y[n];

    for (int i = 0; i < n; i++)
        cin >> x[i] >> y[i];

    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            otr[i][j] = convert(x[i], y[i], x[j], y[j]);

    int ans = 0;

    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
        {
            bool gd = 0;

            for (int u = 0; u < n && !gd; u++)
            {
                if (i == u || j == u)
                    continue;

                for (int t = u + 1; t < n && !gd; t++)
                {
                    if (t == i || t == j)
                        continue;

                    if (x[i] == x[j])
                    {
                        if (x[u] == x[t])
                        {
                            continue;
                        }
                        else if (y[u] == y[t])
                        {
                            if (min(x[u], x[t]) <= x[i] && x[i] <= max(x[u], x[t]) && min(y[i], y[j]) <= y[u] && y[u] <= max(y[i], y[j]))
                            {
                                gd = 1;
                            }

                            continue;
                        }
                        else
                        {
                            if (min(x[u], x[t]) <= x[i] && x[i] <= max(x[u], x[t]))
                            {
                                ld yy = otr[u][t].F * x[i] + otr[u][t].S;

                                if (min(y[i], y[j]) - yy < eps && yy - max(y[i], y[j]) < eps)
                                {
                                    gd = 1;
                                }
                            }

                            continue;
                        }
                    }

                    if (y[i] == y[j])
                    {
                        if (y[u] == y[t])
                        {
                            continue;
                        }
                        else if (x[u] == x[t])
                        {
                            if (min(x[i], x[j]) <= x[u] && x[u] <= max(x[i], x[j]) && min(y[u], y[t]) <= y[i] && y[i] <= max(y[u], y[t]))
                            {
                                gd = 1;
                            }

                            continue;
                        }
                        else
                        {
                            if (min(y[u], y[t]) <= y[i] && y[i] <= max(y[u], y[t]))
                            {
                                ld xx = (y[i] - otr[u][t].S) / otr[u][t].F;

                                if (min(x[i], x[j]) - xx < eps && xx - max(x[i], x[j]) < eps)
                                {
                                    gd = 1;
                                }
                            }

                            continue;
                        }
                    }

                    if (x[u] == x[t])
                    {
                        if (min(x[i], x[j]) <= x[u] && x[u] <= max(x[i], x[j]))
                        {
                            ld yy = otr[i][j].F * x[u] + otr[i][j].S;

                            if (min(y[u], y[t]) - yy < eps && yy - max(y[u], y[t]) < eps)
                            {
                                gd = 1;
                            }
                        }

                        continue;
                    }

                    if (y[u] == y[t])
                    {
                        if (min(y[i], y[j]) <= y[u] && y[u] <= max(y[i], y[j]))
                        {
                            ld xx = (y[u] - otr[i][j].S) / otr[i][j].F;

                            if (min(x[u], x[t]) - xx < eps && xx - max(x[u], x[t]) < eps)
                            {
                                gd = 1;
                            }
                        }

                        continue;
                    }

                    pair <ld, ld> cur = inter(otr[i][j], otr[u][t]);

                    ld lx = min(x[i], x[j]);

                    ld rx = max(x[i], x[j]);

                    ld ly = min(y[i], y[j]);

                    ld ry = max(y[i], y[j]);

                    if (lx - cur.F < eps && cur.F - rx < eps)
                    {
                        if (ly - cur.S < eps && cur.S - ry < eps)
                        {
                            ld lx = min(x[u], x[t]);

                            ld rx = max(x[u], x[t]);

                            ld ly = min(y[u], y[t]);

                            ld ry = max(y[u], y[t]);

                            if (lx - cur.F < eps && cur.F - rx < eps)
                            {
                                if (ly - cur.S < eps && cur.S - ry < eps)
                                {
                                    gd = 1;
                                }
                            }
                        }
                    }
                }
            }

            if (!gd)
                ans++;
        }

    pri(ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 30 ms 1612 KB Output is correct
13 Correct 27 ms 1800 KB Output is correct
14 Correct 21 ms 1472 KB Output is correct
15 Correct 21 ms 1472 KB Output is correct
16 Correct 71 ms 1744 KB Output is correct
17 Correct 50 ms 1736 KB Output is correct
18 Correct 23 ms 1616 KB Output is correct
19 Correct 37 ms 1616 KB Output is correct
20 Correct 138 ms 1732 KB Output is correct
21 Correct 149 ms 1716 KB Output is correct
22 Correct 23 ms 1616 KB Output is correct
23 Correct 26 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 30 ms 1612 KB Output is correct
13 Correct 27 ms 1800 KB Output is correct
14 Correct 21 ms 1472 KB Output is correct
15 Correct 21 ms 1472 KB Output is correct
16 Correct 71 ms 1744 KB Output is correct
17 Correct 50 ms 1736 KB Output is correct
18 Correct 23 ms 1616 KB Output is correct
19 Correct 37 ms 1616 KB Output is correct
20 Correct 138 ms 1732 KB Output is correct
21 Correct 149 ms 1716 KB Output is correct
22 Correct 23 ms 1616 KB Output is correct
23 Correct 26 ms 1616 KB Output is correct
24 Correct 902 ms 19728 KB Output is correct
25 Correct 681 ms 19728 KB Output is correct
26 Correct 868 ms 19728 KB Output is correct
27 Correct 877 ms 19660 KB Output is correct
28 Correct 927 ms 19732 KB Output is correct
29 Correct 574 ms 14388 KB Output is correct
30 Correct 607 ms 15080 KB Output is correct
31 Execution timed out 1085 ms 19664 KB Time limit exceeded
32 Halted 0 ms 0 KB -