Skip to content

Commit d183510

Browse files
authored
[20260203] BOJ / G5 / 랭퍼든 수열쟁이야!! / 한종욱
[20260203] BOJ / G5 / 랭퍼든 수열쟁이야!! / 한종욱
2 parents 9c5d1b3 + 53cd5e4 commit d183510

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+
```
2+
import java.io.*;
3+
import java.util.StringTokenizer;
4+
5+
public class Main {
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
private static int[] arr;
9+
private static boolean[] visited;
10+
private static int N, X, Y, answer;
11+
12+
public static void main(String[] args) throws IOException {
13+
init();
14+
arr[X] = Y-X-1;
15+
arr[Y] = Y-X-1;
16+
visited[Y-X-1] = true;
17+
make(1);
18+
19+
bw.write(answer + "\n");
20+
bw.flush();
21+
bw.close();
22+
br.close();
23+
}
24+
25+
private static void init() throws IOException {
26+
StringTokenizer st = new StringTokenizer(br.readLine());
27+
N = Integer.parseInt(st.nextToken());
28+
X = Integer.parseInt(st.nextToken());
29+
Y = Integer.parseInt(st.nextToken());
30+
31+
arr = new int[2*N+1];
32+
visited = new boolean[N+1];
33+
}
34+
35+
private static void make(int index) {
36+
if (index == 2*N+1) {
37+
answer++;
38+
return;
39+
}
40+
41+
if (arr[index] != 0) make(index+1);
42+
else {
43+
for (int i = 1; i <= N; i++) {
44+
if (!visited[i]) {
45+
if (index+i+1 <= 2*N && arr[index+i+1] == 0) {
46+
arr[index] = i;
47+
arr[index+i+1] = i;
48+
visited[i] = true;
49+
make(index+1);
50+
visited[i] = false;
51+
arr[index] = 0;
52+
arr[index+i+1] = 0;
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
59+
```

0 commit comments

Comments
 (0)