-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10942_chairoi.cpp
More file actions
40 lines (30 loc) ยท 855 Bytes
/
10942_chairoi.cpp
File metadata and controls
40 lines (30 loc) ยท 855 Bytes
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
#include <iostream>
#include <algorithm>
using namespace std;
int ifPalindrom[2001][2001];
int num[2001];
int N, M;
int S, E;
int main(void) {
cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);
cin >> N;
for (int i = 1; i < N + 1; i++) {
cin >> num[i];
ifPalindrom[i][i] = 1;
if (i != 1 && num[i - 1] == num[i]) ifPalindrom[i - 1][i] = 1;
// ํ ์๋ฆฌ ์์ ๋ ์๋ฆฌ๊ฐ ๊ฐ์ ๊ฒฝ์ฐ์ ifPalindrom ๊ฐ ์ ์ฅ
}
for (int i = 2; i < N; i++) {
for (int j = 1; i + j < N + 1; j++) {
if (num[j] == num[i + j] && ifPalindrom[j + 1][i + j - 1] == 1) {
ifPalindrom[j][i + j] = 1;
}
}
}
cin >> M;
for (int i = 0; i < M; i++) {
cin >> S >> E;
cout << ifPalindrom[S][E] << "\n";
}
return 0;
}