답안 #975910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975910 2024-05-06T03:12:16 Z vjudge1 별들과 삼각형 (IZhO11_triangle) C++17
100 / 100
1610 ms 13796 KB
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;

#define FUL(i, a, N) for(int i = a; i < N; i++)
#define FUE(i, a, N) for(int i = a; i <= N; i++)

int N, ans, temp;
pair<int, int> titik[300002];
map<int, vector<int>> titikX, titikY;
map<int, vector<int>> ::iterator it;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> N;
    FUE(i, 1, N){
        cin >> titik[i].fi >> titik[i].se;
    }
    // preprocessing
    titikX[titik[1].fi].pb(titik[1].se);
    titikY[titik[1].se].pb(titik[1].fi);
    titikX[titik[2].fi].pb(titik[2].se);
    titikY[titik[2].se].pb(titik[2].fi);
    FUE(i, 3, N){
        temp = 0;
        it = titikX.find(titik[i].fi);
        if(it != titikX.end()){
            FUL(i, 0, it->se.size()){
                temp += titikY[it->se[i]].size() - 1;
            }
        }
        it = titikY.find(titik[i].se);
        if(it != titikY.end()){
            FUL(i, 0, it->se.size()){
                temp += titikX[it->se[i]].size() - 1;
            }
        }
        temp += titikX[titik[i].fi].size() * titikY[titik[i].se].size();
        ans += temp;
        titikX[titik[i].fi].pb(titik[i].se);
        titikY[titik[i].se].pb(titik[i].fi);
    }
    cout << ans;
    return 0;
}

Compilation message

triangle.cpp: In function 'int main()':
triangle.cpp:9:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define FUL(i, a, N) for(int i = a; i < N; i++)
......
   32 |             FUL(i, 0, it->se.size()){
      |                 ~~~~~~~~~~~~~~~~~~~    
triangle.cpp:32:13: note: in expansion of macro 'FUL'
   32 |             FUL(i, 0, it->se.size()){
      |             ^~~
triangle.cpp:9:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define FUL(i, a, N) for(int i = a; i < N; i++)
......
   38 |             FUL(i, 0, it->se.size()){
      |                 ~~~~~~~~~~~~~~~~~~~    
triangle.cpp:38:13: note: in expansion of macro 'FUL'
   38 |             FUL(i, 0, it->se.size()){
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 323 ms 1452 KB Output is correct
13 Correct 1610 ms 1768 KB Output is correct
14 Correct 10 ms 2392 KB Output is correct
15 Correct 172 ms 9812 KB Output is correct
16 Correct 167 ms 9808 KB Output is correct
17 Correct 146 ms 9808 KB Output is correct
18 Correct 156 ms 9588 KB Output is correct
19 Correct 705 ms 13176 KB Output is correct
20 Correct 408 ms 11776 KB Output is correct
21 Correct 796 ms 13768 KB Output is correct
22 Correct 858 ms 13796 KB Output is correct