1. ๋ฌธ์ ๋ถ์
[๋ฌธ์ ๋งํฌ](https://www.acmicpc.net/problem/1253)
2. ์ ๊ทผ ๋ฐฉ์
- ๋ฐฐ์ด์ ์ ๋์ ํฌ์ธํฐ๋ฅผ ๋๋ค.
- ํ์ฌ Good์ด ๋๋ ์์ธ์ง ๊ฒ์ฐ ํ๋ค. (ํฌ์ธํฐ 2๊ฐ์ ํฉ์ด ํ์ฌ ๊ฒ์ฐ ์ค์ธ ์๋ณด๋ค ํฌ๋ฉด ์ค๋ฅธ์ชฝ ํฌ์ธํฐ๋ฅผ ํ ์นธ ๋ด๋ฆฐ๋ค.) (ํฌ์ธํฐ 2๊ฐ์ ํฉ์ด ํ์ฌ ๊ฒ์ฐ ์ค์ธ ์๋ณด๋ค ์์ผ๋ฉด ์ผ์ชฝ ํฌ์ธํฐ๋ฅผ ํ ์นธ ์ฌ๋ฆฐ๋ค.)
- ์ซ์๋ ์์๋ ๊ฐ๋ฅํ๋ฏ๋ก, ์ ์ฝ์์ด ์ ์ฒด์ ๋ํด์ ๊ณ์ฐ ํด์ผํ๋ค. ์ด๋ O(n^2)์ ์๊ฐ ๋ณต์ก๋๊ฐ ๋ค์ง๋ง, ๊ณ์ฐํด์ผํ ์ด ๋ฐ์ดํฐ ์๊ฐ 2000 ์ด๋ฏ๋ก 10^3 ์ด๋ผ ๊ณ์ฐ์ด ๊ด์ฐฎ๋ค.
3. ์ฝ๋ ๋ถ์
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int [] arr = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr);
int cnt = 0;
for (int i = 0; i < N; i++) {
int temp = arr[i], start = 0, end = N-1;
while (start != end){
if(start == i) {
start++;
continue;
}
if(end == i) {
end--;
continue;
}
if(arr[start] + arr[end] > temp){
end--;
}else if(arr[start] + arr[end] < temp){
start++;
}else if(arr[start] + arr[end] == temp){
cnt++;
break;
}
}
}
System.out.println(cnt);
}
}
0