Skip to content

Commit 31affd1

Browse files
authored
[20250205] BOJ / 골드3 / 지금 만나러 갑니다 / 권혁준
1 parent be9733b commit 31affd1

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st;
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static int nextInt() {return Integer.parseInt(st.nextToken());}
15+
static long nextLong() {return Long.parseLong(st.nextToken());}
16+
static void bwEnd() throws Exception {bw.flush();bw.close();}
17+
18+
// Additional field
19+
20+
21+
22+
public static void main(String[] args) throws Exception {
23+
24+
nextLine();
25+
int N = nextInt(), A = nextInt(), B = nextInt();
26+
boolean[][] D = new boolean[N+1][2];
27+
D[A][0] = true;
28+
D[B][1] = true;
29+
30+
for(int k=1;k<=20;k++) {
31+
int d = 1<<(k-1);
32+
boolean[][] ND = new boolean[N+1][2];
33+
for(int i=1;i<=N;i++) {
34+
for(int j=0;j<2;j++) if(D[i][j]) {
35+
if(i-d > 0) ND[i-d][j] = true;
36+
if(i+d <= N) ND[i+d][j] = true;
37+
}
38+
}
39+
for(int i=1;i<=N;i++) {
40+
D[i][0] = ND[i][0];
41+
D[i][1] = ND[i][1];
42+
if(D[i][0] && D[i][1]) {
43+
bw.write(k+"\n");
44+
bwEnd();
45+
return;
46+
}
47+
}
48+
}
49+
50+
51+
52+
bw.write("-1");
53+
54+
bwEnd();
55+
}
56+
57+
}
58+
59+
```

0 commit comments

Comments
 (0)