Skip to content

Commit 705f56c

Browse files
committed
[Gold I] Title: K번째 수, Time: 24 ms, Memory: 79508 KB -BaekjoonHub
1 parent 29e99a2 commit 705f56c

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Foundation
2+
3+
let n = Int(readLine()!)!
4+
let k = Int(readLine()!)!
5+
6+
var answer = 0
7+
8+
var lo = 1, hi = n*n
9+
10+
while lo <= hi {
11+
let mid = (lo + hi) / 2
12+
let count = countLessEqual(mid)
13+
// 어떤 수 x보다 작은 수의 갯수가 k와 같거나 더 많으므로, 더 작은 x에 대해서도 이를 만족하는 지 검사
14+
if count >= k {
15+
answer = mid
16+
hi = mid - 1
17+
// 어떤 수 x보다 작은 수의 갯수가 k보다 적으므로, 더 큰 x에 대해서 이를 만족하는 지 검사
18+
} else {
19+
lo = mid + 1
20+
}
21+
}
22+
23+
print(answer)
24+
25+
func countLessEqual(_ x: Int) -> Int {
26+
var count = 0
27+
28+
for i in 1...n {
29+
count += min(x/i, n)
30+
}
31+
32+
return count
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# [Gold I] K번째 수 - 1300
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1300)
4+
5+
### 성능 요약
6+
7+
메모리: 79508 KB, 시간: 24 ms
8+
9+
### 분류
10+
11+
이분 탐색, 매개 변수 탐색
12+
13+
### 제출 일자
14+
15+
2025년 11월 1일 14:37:31
16+
17+
### 문제 설명
18+
19+
<p>세준이는 크기가 N×N인 배열 A를 만들었다. 배열에 들어있는 수 A[i][j] = i×j 이다. 이 수를 일차원 배열 B에 넣으면 B의 크기는 N×N이 된다. B를 오름차순 정렬했을 때, B[k]를 구해보자.</p>
20+
21+
<p>배열 A와 B의 인덱스는 1부터 시작한다.</p>
22+
23+
### 입력
24+
25+
<p>첫째 줄에 배열의 크기 N이 주어진다. N은 10<sup>5</sup>보다 작거나 같은 자연수이다. 둘째 줄에 k가 주어진다. k는 min(10<sup>9</sup>, N<sup>2</sup>)보다 작거나 같은 자연수이다.</p>
26+
27+
### 출력
28+
29+
<p>B[k]를 출력한다.</p>
30+

0 commit comments

Comments
 (0)