-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathG20444.java
More file actions
54 lines (40 loc) · 1.36 KB
/
G20444.java
File metadata and controls
54 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package binary_search.moomin;
import java.io.*;
import java.util.*;
/**
* 4번의 가위질로 9개의 조각 만들기
* 1. 색종이는 직사각형이며, 색종이를 자를 때는 한 변에 평행하게 자른다.
* 2. 자르기 시작했으면, 경로 상의 모든 색종이를 자를 때까지 멈추지 않는다.
* 3. 이미 자른 곳을 또 자를 수 없다.
*
* 이분탐색: 가로 * 세로 = 색종이 조각
*/
public class G20444 {
static long N, K;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
// N, K 입력받기
N = Long.parseLong(st.nextToken());
K = Long.parseLong(st.nextToken());
// 가로 * 세로
long left = 0;
long right = N;
long count;
while(left <= right){
long mid = (left + right) / 2;
// 색종이 만들 수 있는지 탐색
count = (mid + 1) * ((N - mid) + 1);
if(count == K) {
System.out.println("YES");
return;
}
if(count > K) {
right = mid - 1;
continue;
}
left = mid + 1;
}
System.out.println("NO");
}
}