8000 Update 7453.cpp · qbinee/basic-algo-lecture@5848ca8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5848ca8

Browse files
Update 7453.cpp
1 parent e8104b5 commit 5848ca8

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

0x13/solutions/7453.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Authored by : scsc3204
2-
// Co-authored by : -
3-
// http://boj.kr/8312a3fc055744dab8088197ac57d52a
2+
// Co-authored by : BaaaaaaaaaaarkingDog
3+
// http://boj.kr/45af92e52b8a4d24b52494518812dccd
44
#include <bits/stdc++.h>
55
typedef long long ll;
66
using namespace std;
@@ -16,18 +16,22 @@ int main(){
1616
cin >> n;
1717
for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
1818

19-
int cnt = 0;
2019
for(int i = 0; i < n; i++)
21-
for(int j = 0; j < n; j++) {
22-
ab[cnt] = a[i] + b[j];
23-
cd[cnt++] = c[i] + d[j];
24-
}
25-
26-
sort(ab, ab + n*n);
20+
for(int j = 0; j < n; j++)
21+
cd[i*n + j] = c[i] + d[j];
22+
2723
sort(cd, cd + n*n);
2824

2925
ll ans = 0;
30-
for(int i = 0; i < n*n; i++)
31-
ans += upper_bound(cd, cd + n*n, -ab[i]) - lower_bound(cd, cd + n*n, -ab[i]);
26+
for(int i = 0; i < n; i++)
27+
for(int j = 0; j < n; j++)
28+
ans += upper_bound(cd, cd + n*n, -a[i] - b[j]) - lower_bound(cd, cd + n*n, -a[i] - b[j]);
29+
3230
cout << ans;
33-
}
31+
}
32+
/*
33+
a[i]+b[j]들을 저장할 ab 배열을 별도로 선언하지 않아도 되지만, 선언해서 정렬한 후 크기 순으로
34+
탐색을 할 경우에는 cache hit이 올라가서 속도가 빨라짐.
35+
코드 : http://boj.kr/8312a3fc055744dab8088197ac57d52a
36+
설명 : https://www.acmicpc.net/board/view/74585
37+
*/

0 commit comments

Comments
 (0)
0