forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10942.cpp
More file actions
39 lines (31 loc) · 730 Bytes
/
10942.cpp
File metadata and controls
39 lines (31 loc) · 730 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
// Authored by : Hot6Mania
// Co-authored by : -
// http://boj.kr/2b8c4fa5fed849008ff86212e8be86b3
#include <bits/stdc++.h>
using namespace std;
int n;
int a[2010], d[2010][2010];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) {
d[i][i] = 1;
if (a[i - 1] == a[i]) d[i - 1][i] = 1;
}
for (int gap = 2; gap < n; ++gap) {
for (int i = 1; i <= n - gap; ++i) {
int s = i, e = i + gap;
if (a[s] == a[e] && d[s + 1][e - 1]) d[s][e] = 1;
}
}
int t;
cin >> t;
while (t--) {
int s, e;
cin >> s >> e;
cout << d[s][e] << '\n';
}
return 0;
}