Skip to content

Commit 3638939

Browse files
authored
Merge pull request #1876 from AlgorithmWithGod/JHLEE325
[20260203] BOJ / G5 / 랭퍼든 수열쟁이야!! / 이준희
2 parents 26d524e + 3c84d44 commit 3638939

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static int n, x, y, count;
8+
static int[] arr;
9+
static boolean[] used;
10+
11+
public static void main(String[] args) throws IOException {
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
StringTokenizer st = new StringTokenizer(br.readLine());
14+
15+
n = Integer.parseInt(st.nextToken());
16+
x = Integer.parseInt(st.nextToken());
17+
y = Integer.parseInt(st.nextToken());
18+
19+
arr = new int[2 * n + 1];
20+
used = new boolean[n + 1];
21+
22+
int fixedNum = y - x - 1;
23+
arr[x] = arr[y] = fixedNum;
24+
used[fixedNum] = true;
25+
26+
check(1);
27+
28+
System.out.println(count);
29+
}
30+
31+
static void check(int pos) {
32+
if (pos == 2 * n + 1) {
33+
count++;
34+
return;
35+
}
36+
37+
if (arr[pos] != 0) {
38+
check(pos + 1);
39+
return;
40+
}
41+
42+
for (int i = 1; i <= n; i++) {
43+
if (used[i]) continue;
44+
45+
if (pos + i + 1 <= 2 * n && arr[pos + i + 1] == 0) {
46+
arr[pos] = arr[pos + i + 1] = i;
47+
used[i] = true;
48+
49+
check(pos + 1);
50+
51+
arr[pos] = arr[pos + i + 1] = 0;
52+
used[i] = false;
53+
}
54+
}
55+
}
56+
}
57+
```

0 commit comments

Comments
 (0)