博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #410 (Div. 2) B. Mike and strings
阅读量:6637 次
发布时间:2019-06-25

本文共 1407 字,大约阅读时间需要 4 分钟。

B. Mike and strings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".

Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal?

Input

The first line contains integer n (1 ≤ n ≤ 50) — the number of strings.

This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50.

Output

Print the minimal number of moves Mike needs in order to make all the strings equal or print  - 1 if there is no solution.

Examples
input
4 xzzwo zwoxz zzwox xzzwo
output
5
input
2 molzv lzvmo
output
2
input
3 kc kc kc
output
0
input
3 aa aa ab
output
-1 给你n个字符串,让你找怎么处理使你移动的个数最小,如果移动后还不相等就输出-1
#include 
using namespace std;int main(){int n=0;cin>>n;string s[55];for(int i=0;i
>s[i];int mi=1<<30;int l=s[0].length();for(int i=0;i
=l){cout<<"-1"<
View Code

 

转载于:https://www.cnblogs.com/BobHuang/p/6822752.html

你可能感兴趣的文章
settimeout 推荐的最小值
查看>>
MySQL 常用命令
查看>>
HttpClient4上传文件
查看>>
centos6.4和Ubuntu14.04搭建SNMP服务
查看>>
为微信小程序增加mixin扩展
查看>>
敏感信息识别方法探究
查看>>
创建一个可执行的python脚本
查看>>
听云APP 图表分析
查看>>
Oracle排名函数运用实例
查看>>
【推荐】[网址]PHP各种开源网站系统、cms系统一览[持续更新]
查看>>
整合 Apache 与 Tomcat
查看>>
螺旋矩阵打印java实现
查看>>
centos下java调用命令报 java.io.IOException: error=2, No such file or directory的错误
查看>>
Centos7 修改主机名
查看>>
javascript选择后弹出框消失
查看>>
JDK 1.7 HashMap原理及源码解析
查看>>
绘图UIGraphicsGetCurrentContext返回为空?
查看>>
FMDB使用
查看>>
Exchange Server2010五大角色
查看>>
博为峰Java技术题 ——JavaSE Scanner类Ⅰ
查看>>