Submission #879931

# Submission time Handle Problem Language Result Execution time Memory
879931 2023-11-28T10:44:59 Z heeheeheehaaw Star triangles (IZhO11_triangle) C++17
100 / 100
420 ms 10172 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

map<int, vector<int>> aux;
vector<int> v;
map<int, int> fr;

signed main()
{
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++)
    {
        int x, y;
        cin>>x>>y;
        aux[x].push_back(y);
        fr[y]++;
    }

    int rez = 0;
    for(auto i : aux)
    {
        v = i.second;
        sort(v.begin(), v.end());
        int cnt = -1;
        for(int j = 0; j < v.size(); j++)
        {
            cnt++;
            rez += cnt * (fr[v[j]] - 1);
        }
        cnt = -1;
        for(int j = (int)v.size() - 1; j >= 0; j--)
        {
            cnt++;
            rez += cnt * (fr[v[j]] - 1);
        }
    }

    cout<<rez;
    return 0;
}

Compilation message

triangle.cpp: In function 'int main()':
triangle.cpp:28:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int j = 0; j < v.size(); j++)
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 12 ms 1196 KB Output is correct
13 Correct 9 ms 1372 KB Output is correct
14 Correct 13 ms 1884 KB Output is correct
15 Correct 129 ms 6344 KB Output is correct
16 Correct 142 ms 6484 KB Output is correct
17 Correct 138 ms 6460 KB Output is correct
18 Correct 133 ms 6480 KB Output is correct
19 Correct 420 ms 9676 KB Output is correct
20 Correct 254 ms 8308 KB Output is correct
21 Correct 381 ms 9812 KB Output is correct
22 Correct 403 ms 10172 KB Output is correct