You can enumerate all the start and end points in a brute force manner.
I thought too much about this question, but I did not expect the simplest starting point of the violent enumeration... You should first think of the simplest way to go deeper.
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<map>#include<set>#include<vector>#include<algorithm>#include<stack>#include<queue>using namespace std;#define INF 1000000000#define eps 1e-8#define pii pair<int,int>#define LL long long intchar s[500];int k,ans;void check(int b,int e){ int l=e-b+1; if(l&1) return; else { int t=l/2; for(int i=b;i<b+t;i++) { if(s[i]==s[t+i]||s[t+i]==0) continue; else return; } ans=max(ans,l); return; }}int main(){ //freopen("in7.txt","r",stdin); //freopen("out.txt","w",stdout); scanf("%s",s); scanf("%d",&k); int len=strlen(s); int lens=len+k; ans=0; for(int i=0;i<lens-1;i++) { for(int j=i+1;j<=lens-1;j++) { check(i,j); } } printf("%d\n",ans); //fclose(stdin); //fclose(stdout); return 0;}
Codeforces round #253 (Div. 2) B (brute force enumeration)