This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
const int N = 1e2+10;
const int M = 101;
const LL INF = 1e9;
const LL LINF = 2e18;
const LL MOD = 4294967296;
const double PI = 3.141592653589793;
string s;
bool check(int l1,int r1,int l2,int r2){
string s1 = "",s2 = "";
for(int i=l1;i<=r1;i++)
s1 += s[i];
for(int i=l2;i<=r2;i++)
s2 += s[i];
return s1==s2;
}
int solve(int l,int r){
if(l>r)
return 0;
for(int i=l;i<(l+r+1)/2;i++)
if(check(l,i,r-(i-l),r))
return 2+solve(i+1,r-(i-l)-1);
return 1;
}
int main(){
//freopen("out.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--){
cin>>s;
int n = s.size();
printf("%d\n",solve(0,n-1));
}
}
Compilation message (stderr)
palindromic.cpp: In function 'int main()':
palindromic.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d",&t);
| ~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |