-
Notifications
You must be signed in to change notification settings - Fork 0
/
10942.cpp
66 lines (64 loc) · 1.29 KB
/
10942.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FastIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define MAXN 2000
int n,m;
int arr[MAXN];
int dp[MAXN][MAXN];
bool isRange(int l, int r) {
if(l < 0 || l > n-1 || r <0 || r > n-1) {
return false;
}
if(l > r) {
return false;
}
return true;
}
bool isPalindrome(int l, int r) {
if(!isRange(l,r)) {
return false;
}
if(abs(l-r) <= 1) {
if(arr[l] == arr[r]) {
return true;
} else {
return false;
}
}
//abs(l-r)이 2이상임!
if(dp[l+1][r-1] == true) {
if(arr[l] == arr[r]) {
return true;
}
}
return false;
}
int main(void) {
FastIO;
cin >> n;
for(int i=0; i<n; i++) {
cin >> arr[i];
}
for(int i=0; i<n; i++) {
int di = 0;
while(isPalindrome(i-di, i+di)) {
dp[i-di][i+di] = true;
di++;
}
}
for(int i=0; i<n; i++) {
int di = 0;
while(isPalindrome(i-di, (i+1)+di)) {
dp[i-di][i+1+di] = true;
di++;
}
}
cin >> m;
for(int i=0; i<m; i++) {
int a, b;
cin >> a >> b;
cout << dp[a-1][b-1] << endl;
}
return 0;
}