Skip to content

Commit 23592eb

Browse files
authored
Merge pull request #334 from AlgorithmWithGod/lkhyun
BOJ / G4 / 팰린드롬? / 이강현
2 parents a5aba95 + a24e687 commit 23592eb

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
public class Main {
5+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
6+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
7+
static StringTokenizer st;
8+
static int[][] dp;
9+
static int N,M;
10+
static int[] arr;
11+
public static void main(String[] args) throws IOException {
12+
N = Integer.parseInt(br.readLine());
13+
arr = new int[N+1];
14+
15+
st = new StringTokenizer(br.readLine());
16+
for (int i = 1; i <= N; i++) {
17+
arr[i] = Integer.parseInt(st.nextToken());
18+
}
19+
20+
dp = new int[N+1][N+1];
21+
for (int i = 1; i <= N; i++) {
22+
dp[i][i] = 1;
23+
}
24+
for (int i = 1; i < N; i++) {
25+
if(arr[i] == arr[i+1]){
26+
dp[i][i+1] = 1;
27+
}
28+
}
29+
for (int i = 2; i < N; i++) {
30+
for (int j = 1; j+i <= N; j++) {
31+
if(arr[j] == arr[j+i]){
32+
dp[j][j+i] = dp[j+1][j+i-1];
33+
}else{
34+
dp[j][j+i] = 0;
35+
}
36+
}
37+
}
38+
M = Integer.parseInt(br.readLine());
39+
for (int i = 0; i < M; i++) {
40+
st = new StringTokenizer(br.readLine());
41+
int S = Integer.parseInt(st.nextToken());
42+
int E = Integer.parseInt(st.nextToken());
43+
bw.write(dp[S][E] + "\n");
44+
}
45+
bw.close();
46+
}
47+
}
48+
49+
```

0 commit comments

Comments
 (0)