Codeforces problem

Joined
Apr 24, 2022
Messages
1
Reaction score
0
I've been practicing interview and cp question for some time now and I'm really stuck at this problem for a really long a time
The answer
#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);
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 example
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,790
Messages
2,569,637
Members
45,346
Latest member
EstebanCoa

Latest Threads

Top