From 28ab8815e41681b157fd21818ae81f70f9501007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EC=B1=84=EC=9B=90?= <87516785+chairoi@users.noreply.github.com> Date: Mon, 18 Sep 2023 23:41:07 +0900 Subject: [PATCH] =?UTF-8?q?[BOJ]=2010942=20=ED=8C=B0=EB=A6=B0=EB=93=9C?= =?UTF-8?q?=EB=A1=AC=3F=20(cpp)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week01/10942_chairoi.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 week01/10942_chairoi.cpp diff --git a/week01/10942_chairoi.cpp b/week01/10942_chairoi.cpp new file mode 100644 index 0000000..c6d0e5d --- /dev/null +++ b/week01/10942_chairoi.cpp @@ -0,0 +1,40 @@ +#include +#include + +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; +}