답안 #968025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968025 2024-04-23T07:00:50 Z tset 별들과 삼각형 (IZhO11_triangle) C++14
100 / 100
223 ms 21408 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pii pair<int, int>

int firstEqual(vector<int>& v, int nb)
{
    int pos = -1;
    int pas = 1 << 20; 
    while(pas>0)
    {
        int test = pos + pas;
        if(test < v.size())
        {
            if(v[test] < nb)
            {
                pos += pas;
            }
        }
        pas /= 2;
    }
    return pos +1;
}

int nbAxis(vector<int>& v, int nb)
{
    return firstEqual(v, nb+1) - firstEqual(v, nb);
}

signed main()
{
    int N;
    scanf("%lld", &N);
    vector<int > X, Y;
    vector<pii> coords;
    for(int iN = 0; iN < N; iN++)
    {
        int x, y;
        scanf("%lld%lld", &x, &y);
        X.push_back(x);
        Y.push_back(y);
        coords.push_back({x, y});
    }

    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    int ans= 0;
    for(pii coord : coords)
    {
        int x = coord.first;
        int y = coord.second;
        int cx = nbAxis(X, x) -1;
        int cy = nbAxis(Y, y) -1;
        ans += cx * cy;
    }
    printf("%lld\n", ans);
}

Compilation message

triangle.cpp: In function 'long long int firstEqual(std::vector<long long int>&, long long int)':
triangle.cpp:16:17: 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]
   16 |         if(test < v.size())
      |            ~~~~~^~~~~~~~~~
triangle.cpp: In function 'int main()':
triangle.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%lld", &N);
      |     ~~~~~^~~~~~~~~~~~
triangle.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%lld%lld", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 444 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 4 ms 1216 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 4 ms 1116 KB Output is correct
15 Correct 67 ms 5860 KB Output is correct
16 Correct 72 ms 6324 KB Output is correct
17 Correct 63 ms 5824 KB Output is correct
18 Correct 62 ms 5812 KB Output is correct
19 Correct 200 ms 21408 KB Output is correct
20 Correct 136 ms 11176 KB Output is correct
21 Correct 223 ms 21152 KB Output is correct
22 Correct 218 ms 21148 KB Output is correct