File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments