Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.
#include <bits/stdc++.h>
using namespace std;
string s[51];
int main()
{
int n, t, ans;
ans = INT_MAX;
cin>>n;
string temp;
for(int i=0; i<n; i++)
cin>>s[i];
for(int i=0; i<n; i++)
{
t = 0;
for(int j=0; j<n; j++)
{
temp=s[j]+s[j];
if(temp.find(s[i])==string::npos)
{
cout<<-1<<endl;
return 0;
}
t += temp.find(s[i]);
}
ans = t<ans?t:ans;
}
cout<<ans;
return 0;
}
📦 Looking for Codeforces Round 410 Div Problem Mike? Check the best deals on Amazon.
🛒 Shop Codeforces Round 410 Div Problem Mike on Amazon
As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.
Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.
#include <bits/stdc++.h>
using namespace std;
string s[51];
int main()
{
int n, t, ans;
ans = INT_MAX;
cin>>n;
string temp;
for(int i=0; i<n; i++)
cin>>s[i];
for(int i=0; i<n; i++)
{
t = 0;
for(int j=0; j<n; j++)
{
temp=s[j]+s[j];
if(temp.find(s[i])==string::npos)
{
cout<<-1<<endl;
return 0;
}
t += temp.find(s[i]);
}
ans = t<ans?t:ans;
}
cout<<ans;
return 0;
}
📦 Looking for Codeforces Round 410 Div Problem Mike? Check the best deals on Amazon.
🛒 Shop Codeforces Round 410 Div Problem Mike on Amazon
As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.