Submission #974886

# Submission time Handle Problem Language Result Execution time Memory
974886 2024-05-04T06:16:28 Z vjudge1 Star triangles (IZhO11_triangle) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;

long long count(const vector<pair<int, int>> &points)
{
    long long count = 0;
    int n = points.size();

    map<int, int> rowCount;

    for (const auto &point : points)
    {
        rowCount[point.second]++;
    }

    for (int i = 0; i < n; ++i)
    {
        int x1 = points[i].first;
        int y1 = points[i].second;

        map<int, int> rightCount;
        for (int j = i + 1; j < n; ++j)
        {
            int x2 = points[j].first;
            int y2 = points[j].second;

            if (y2 == y1)
            {
                rightCount[x2]++;
            }
        }

        for (auto &row : rowCount)
        {
            int y2 = row.first;
            int countOnRow = row.second;

            if (y2 <= y1)
            {
                count += (countOnRow - 1) * rightCount[y2];
            }
            else
            {
                count += countOnRow * rightCount[y2];
            }
        }
    }

    return count;
}

void solve()
{
    cin >> n;
    vector<pair<int, int>> point(n);
    for (int i = 0; i < n; i++)
    {
        cin >> point[i].first >> point[i].second;
    }

    cout << count(point);
}
int main()
{
    int t = 1;

    while (t--)
    {
        solve();
    }
}

Compilation message

triangle.cpp: In function 'long long int count(const std::vector<std::pair<int, int> >&)':
triangle.cpp:20:13: warning: unused variable 'x1' [-Wunused-variable]
   20 |         int x1 = points[i].first;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -