[伯俊]10942パリン症候群?
白駿10942パリン症候群?
https://www.acmicpc.net/problem/10942
パリンドロム:逆さまに読んでも正しく読める文、単語、数字、文字列など
https://www.acmicpc.net/problem/10942
パリンドロム:逆さまに読んでも正しく読める文、単語、数字、文字列など
#include <iostream>
#include <cstring>
using namespace std;
const int MAXN = 2001;
int num[MAXN];
int cache[MAXN][MAXN];
bool palindrome(int s, int e) {
if (s >= e) return true;
int& ret = cache[s][e];
if (ret != -1) return ret;
if (num[s] == num[e])
return ret = palindrome(s + 1, e - 1);
else
return ret = false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
for (int i = 0; i < MAXN; ++i)
memset(cache[i], -1, sizeof(cache[i]));
int N, M;
cin >> N ;
for (int i = 1; i <= N; ++i)
cin >> num[i];
cin >> M;
for (int i = 0; i < M; ++i) {
int s, e;
cin >> s >> e;
cout << palindrome(s, e) << "\n";
}
return 0;
}
Reference
この問題について([伯俊]10942パリン症候群?), 我々は、より多くの情報をここで見つけました https://velog.io/@sunjoo9912/백준-10942-팰린드롬テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol