-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10942.cpp
More file actions
59 lines (48 loc) · 1.06 KB
/
Copy path10942.cpp
File metadata and controls
59 lines (48 loc) · 1.06 KB
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
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int arr[2001];
bool palindrom[2001][2001] = {
false,
};
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
int n, m, s, e;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
cin >> m;
for (int i = 1; i <= n; i++) // 길이가 1일 때
{
palindrom[i][i] = true;
}
for (int i = 1; i <= n - 1; i++) // 길이가 2일 때
{
if (arr[i] == arr[i + 1])
palindrom[i][i + 1] = true;
}
for (int i = n - 1; i >= 1; i--)
{
for (int j = i + 2; j <= n; j++) // 길이가 3이상일 때
{
if (arr[i] == arr[j] && palindrom[i + 1][j - 1] == true)
{
palindrom[i][j] = true;
}
}
}
for (int i = 0; i < m; i++)
{
cin >> s >> e;
cout << palindrom[s][e]
<< '\n';
}
return 0;
}