[문제 링크] : https://www.acmicpc.net/problem/7453
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N;
int A[4001];
int B[4001];
int C[4001];
int D[4001];
long long Ans;
vector<long long> V;
int main(){
cin >> N;
for(int i=0; i<N; i++){
cin >> A[i] >> B[i] >> C[i] >> D[i];
}
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
V.push_back(A[i] + B[j]);
}
}
sort(V.begin(), V.end());
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
long long tmp = C[i] + D[j];
long long s = lower_bound(V.begin(), V.end(), -tmp) - V.begin();
long long e = upper_bound(V.begin(), V.end(), -tmp) - V.begin();
if(-tmp == V[s]){
Ans += e - s;
}
}
}
cout << Ans << "\n";
return 0;
}
'알고리즘' 카테고리의 다른 글
[알고리즘] 백준 16431 - 베시와 데이지 (C++) (0) | 2025.02.01 |
---|---|
[알고리즘] 백준 10775 - 공항 (C++) (0) | 2025.01.31 |
[알고리즘] 백준 22864 - 피로도 (C++) (0) | 2025.01.29 |
[알고리즘] 백준 26307 - Correct (C++) (0) | 2025.01.28 |
[알고리즘] 백준 17406 - 배열 돌리기 4 (C++) (0) | 2025.01.27 |