- Joined
- Apr 24, 2022

- Messages
- 1

- Reaction score
- 0

### Problem - 798B - Codeforces

Codeforces. Programming competitions and contests, programming community

codeforces.com

#include<iostream>

using namespace std;

int main()

{

int n;

cin>>n;

string s[n];

int m=0;

int ans=0;

for(int i=0;i<n;i++)

{

cin>>s

*;*

}

for(int i=0;i<n;i++)

{

for(int j=0;j<n-1;j++)

{

m=string(s[j]+s[j]).find(s

}

for(int i=0;i<n;i++)

{

for(int j=0;j<n-1;j++)

{

m=string(s[j]+s[j]).find(s

*);*

ans+=m;

}

}

cout<<ans<<endl;

4

xzzwo

zwoxz

zzwox

xzzwo

My answer is 10 however the optimal solution is 5

How do I get about it and what do i need to do

}

What my code is lacking is the most optimal solution

For exampleans+=m;

}

}

cout<<ans<<endl;

4

xzzwo

zwoxz

zzwox

xzzwo

My answer is 10 however the optimal solution is 5

How do I get about it and what do i need to do

}

What my code is lacking is the most optimal solution

For example