Submission #335616

# Submission time Handle Problem Language Result Execution time Memory
335616 2020-12-13T09:40:21 Z StanCatalin Star triangles (IZhO11_triangle) C++14
100 / 100
537 ms 14956 KB
#include <iostream>
#include <algorithm>
#include <fstream>
#include <map>
#include <vector>

using namespace std;

ifstream in("triangles.in");
ofstream out("triangles.out");

const int dim = 3e5 + 5;

int n,lin[dim],col[dim];
pair<int,int> a[dim];
vector<int> linie;
vector<int> coloana;
int cnt_linie,cnt_coloana;
map<int,int> li;
map<int,int> co;

void Normalizare()
{
    sort(linie.begin(), linie.end());
    for (auto y:linie)
    {
        if (li[y] == 0)
        {
            li[y] = cnt_linie++;
        }
    }

    sort(coloana.begin(), coloana.end());
    for (auto y:coloana)
    {
        if (co[y] == 0)
        {
            co[y] = cnt_coloana++;
        }
    }
}

int main()
{
    cin >> n;
    for (int i=1; i<=n; i++)
    {
        cin >> a[i].first >> a[i].second;
        linie.push_back(a[i].first);
        coloana.push_back(a[i].second);
    }

    Normalizare();

    for (int i=1; i<=n; i++)
    {
        a[i].first = li[a[i].first];
        a[i].second = co[a[i].second];
    }

    for (int i=1; i<=n; i++)
    {
        lin[a[i].first]++;
        col[a[i].second]++;
    }

    int ans = 0;
    for (int i=1; i<=n; i++)
    {
        ans += (lin[a[i].first] - 1) * (col[a[i].second] - 1);
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 13 ms 1132 KB Output is correct
13 Correct 16 ms 1260 KB Output is correct
14 Correct 19 ms 1644 KB Output is correct
15 Correct 187 ms 7184 KB Output is correct
16 Correct 201 ms 7844 KB Output is correct
17 Correct 210 ms 7320 KB Output is correct
18 Correct 182 ms 7184 KB Output is correct
19 Correct 492 ms 13952 KB Output is correct
20 Correct 359 ms 11416 KB Output is correct
21 Correct 537 ms 14956 KB Output is correct
22 Correct 537 ms 14848 KB Output is correct