Skip to content

Commit e07a894

Browse files
committed
[Silver III] Title: 두 수의 합, Time: 172 ms, Memory: 20540 KB -BaekjoonHub
1 parent ceb1d22 commit e07a894

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [Silver III] 두 수의 합 - 3273
2+
3+
[문제 링크](https://www.acmicpc.net/problem/3273)
4+
5+
### 성능 요약
6+
7+
메모리: 20540 KB, 시간: 172 ms
8+
9+
### 분류
10+
11+
정렬, 두 포인터
12+
13+
### 제출 일자
14+
15+
2026년 1월 4일 09:42:48
16+
17+
### 문제 설명
18+
19+
<p>n개의 서로 다른 양의 정수 a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n</sub>으로 이루어진 수열이 있다. a<sub>i</sub>의 값은 1보다 크거나 같고, 1000000보다 작거나 같은 자연수이다. 자연수 x가 주어졌을 때, a<sub>i</sub> + a<sub>j</sub> = x (1 ≤ i < j ≤ n)을 만족하는 (a<sub>i</sub>, a<sub>j</sub>)쌍의 수를 구하는 프로그램을 작성하시오.</p>
20+
21+
### 입력
22+
23+
<p>첫째 줄에 수열의 크기 n이 주어진다. 다음 줄에는 수열에 포함되는 수가 주어진다. 셋째 줄에는 x가 주어진다. (1 ≤ n ≤ 100000, 1 ≤ x ≤ 2000000)</p>
24+
25+
### 출력
26+
27+
<p>문제의 조건을 만족하는 쌍의 개수를 출력한다.</p>
28+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
let input = require('fs').readFileSync('./dev/stdin').toString().trim().split('\n');
2+
let N = Number(input[0]);
3+
let arr = input[1].split(' ').map(Number);
4+
let M = Number(input[2]);
5+
6+
function solution(N, arr, M) {
7+
let indexArr = Array(100001).fill(0);
8+
let cnt = 0;
9+
10+
arr.forEach((a) => {
11+
indexArr[a] = 1;
12+
});
13+
14+
for (let i = 0; i < M / 2; i++) {
15+
if (indexArr[i] === 1 && indexArr[M - i] === 1) {
16+
cnt++;
17+
}
18+
}
19+
20+
console.log(cnt);
21+
}
22+
23+
solution(N, arr, M);

0 commit comments

Comments
 (0)