Submission #397645

# Submission time Handle Problem Language Result Execution time Memory
397645 2021-05-02T16:40:52 Z MrRobot_28 Geometrija (COCI21_geometrija) C++17
110 / 110
198 ms 16068 KB
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define int long long
#define sz(a) (int)a.size()
const int mod = 1e9 + 7;
const int N = 2e5+ 100;
int crossproduct(pair <int, int> a, pair <int, int> b)
{
    return a.X * b.Y - a.Y * b.X;
}
bool cmp(pair <pair <int, int>, int> a, pair <pair <int, int>, int> b)
{
    if(a.X.X * b.X.X < 0)
    {
        return a.X.X > b.X.X;
    }
    if(a.X.X == 0)
    {
        return b.X.X < 0 || a.X.Y > 0;
    }
    if(b.X.X == 0)
    {
        return a.X.X > 0 && b.X.Y < 0;
    }
    return crossproduct(a.X, b.X) < 0;
}
signed main()
{
  //  ifstream cin("input1.txt.4c");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <pair <int, int> > x(n);
    int cnt[n][n];
    int cnt1[n][n];
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cnt1[i][j] = 0;
            cnt[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++)
    {
        cin >> x[i].X >> x[i].Y;
    }
    vector <int> coun(n);
    for(int i = 0; i < n; i++)
    {
        vector <pair <pair <int, int>, int> > t;
        for(int j = 0; j < n; j++)
        {
            if(i != j)
            {
                t.push_back({{x[j].X - x[i].X, x[j].Y - x[i].Y}, j});
            }
        }
        sort(t.begin(), t.end(), cmp);
        int it = 0;
        //cout << i << "\n";
        for(int j = 0; j < n - 1; j++)
        {
        //    cout << t[j].X.X << " " << t[j].X.Y << " " << t[j].Y << "\n";
            while(it != n - 1 + j && (j == it  || crossproduct(t[j].X, t[it % (n - 1)].X) < 0))
            {
                it++;
            }
            cnt1[i][t[j].Y] = (n - 1 + j) - it;
          //  cout << "A " << it << " ";
            coun[j] = (n - 1 + j) - it;
            //cout << coun[j] << "\n";
        }
        int sum = 0;
        it = 1;
        for(int j = 1; j < n - 1; j++)
        {
            sum += coun[j];
        }
        for(int j = 0; j < n - 1; j++)
        {
            while(it != n - 1 + j && (it <= j || crossproduct(t[j].X, t[it % (n - 1)].X) < 0))
            {
                sum -= coun[it % (n - 1)];
                it++;
            }
            int k = it - j - 1;
         //   cout << i << " " << t[j].Y << " " << sum + k * (k - 1) / 2 << "\n";
            cnt[i][t[j].Y] += sum + k * (k - 1) / 2;
            sum += coun[j];
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            int d = cnt[i][j] + cnt[j][i];
            int f = cnt1[i][j];
            int f1 = n - 2 - f;
            d -= f * (f - 1) / 2;
            d -= f1 * (f1 - 1) / 2;
      //      cout << d << " ";
            if(d == (n - 2) * (n - 3) / 2)
            {
                ans++;
            }
        }
        //cout << "\n";
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 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 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 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 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 844 KB Output is correct
13 Correct 7 ms 956 KB Output is correct
14 Correct 6 ms 716 KB Output is correct
15 Correct 5 ms 716 KB Output is correct
16 Correct 7 ms 844 KB Output is correct
17 Correct 7 ms 844 KB Output is correct
18 Correct 7 ms 940 KB Output is correct
19 Correct 7 ms 844 KB Output is correct
20 Correct 7 ms 844 KB Output is correct
21 Correct 7 ms 844 KB Output is correct
22 Correct 7 ms 844 KB Output is correct
23 Correct 7 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 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 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 844 KB Output is correct
13 Correct 7 ms 956 KB Output is correct
14 Correct 6 ms 716 KB Output is correct
15 Correct 5 ms 716 KB Output is correct
16 Correct 7 ms 844 KB Output is correct
17 Correct 7 ms 844 KB Output is correct
18 Correct 7 ms 940 KB Output is correct
19 Correct 7 ms 844 KB Output is correct
20 Correct 7 ms 844 KB Output is correct
21 Correct 7 ms 844 KB Output is correct
22 Correct 7 ms 844 KB Output is correct
23 Correct 7 ms 844 KB Output is correct
24 Correct 189 ms 16024 KB Output is correct
25 Correct 195 ms 16048 KB Output is correct
26 Correct 186 ms 16016 KB Output is correct
27 Correct 190 ms 15948 KB Output is correct
28 Correct 192 ms 15948 KB Output is correct
29 Correct 129 ms 11124 KB Output is correct
30 Correct 150 ms 11736 KB Output is correct
31 Correct 183 ms 15996 KB Output is correct
32 Correct 184 ms 15948 KB Output is correct
33 Correct 182 ms 16004 KB Output is correct
34 Correct 198 ms 16012 KB Output is correct
35 Correct 188 ms 16068 KB Output is correct
36 Correct 187 ms 15948 KB Output is correct
37 Correct 179 ms 16048 KB Output is correct
38 Correct 179 ms 15948 KB Output is correct
39 Correct 187 ms 16020 KB Output is correct
40 Correct 192 ms 15948 KB Output is correct
41 Correct 194 ms 15948 KB Output is correct
42 Correct 193 ms 15948 KB Output is correct