[Gold IV] Title: 좋다, Time: 676 ms, Memory: 40724 KB -BaekjoonHub

This commit is contained in:
SSUM
2026-03-30 16:07:11 +09:00
parent 4bc7b67e19
commit 5e3f398fa0
2 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
# [Gold IV] 좋다 - 1253
[문제 링크](https://www.acmicpc.net/problem/1253)
### 성능 요약
메모리: 40724 KB, 시간: 676 ms
### 분류
자료 구조, 정렬, 이분 탐색, 두 포인터
### 제출 일자
2026년 3월 30일 16:06:57
### 문제 설명
<p>N개의 수 중에서 어떤 수가 다른 수 두 개의 합으로 나타낼 수 있다면 그 수를 “좋다(GOOD)”고 한다.</p>
<p>N개의 수가 주어지면 그 중에서 좋은 수의 개수는 몇 개인지 출력하라.</p>
<p>수의 위치가 다르면 값이 같아도 다른 수이다.</p>
### 입력
<p>첫째 줄에는 수의 개수 N(1 ≤ N ≤ 2,000), 두 번째 줄에는 i번째 수를 나타내는 A<sub>i</sub>가 N개 주어진다. (|A<sub>i</sub>| ≤ 1,000,000,000, A<sub>i</sub>는 정수)</p>
### 출력
<p>좋은 수의 개수를 첫 번째 줄에 출력한다.</p>

View File

@@ -0,0 +1,38 @@
import sys
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from functools import lru_cache
from typing import List, Optional
def solve():
# 입력 처리
n = int(input())
arr = list(map(int, input().split()))
# 풀이 작성
arr.sort()
total = 0
if(n==1 or n==2):
print(total)
else:
for i in range(n):
left = 0
right = n-1
goal = arr[i]
while (left<right):
if(arr[left]+arr[right]==goal):
if(left!=i and right!=i):
total+=1
break
elif (left==i):
left+=1
else:
right-=1
elif(arr[left]+arr[right]>goal):
right-=1
else:
left+=1
print(total)
if __name__ == "__main__":
solve()