C. Dasha and Password
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements:

  • There is at least one digit in the string,
  • There is at least one lowercase (small) letter of the Latin alphabet in the string,
  • There is at least one of three listed symbols in the string: '#', '*', '&'.

Considering that these are programming classes it is not easy to write the password.

For each character of the password we have a fixed string of length m, on each of these n strings there is a pointer on some character. The i-th character displayed on the screen is the pointed character in the i-th string. Initially, all pointers are on characters with indexes 1in the corresponding strings (all positions are numbered starting from one).

During one operation Dasha can move a pointer in one string one character to the left or to the right. Strings are cyclic, it means that when we move the pointer which is on the character with index 1 to the left, it moves to the character with the index m, and when we move it to the right from the position m it moves to the position 1.

You need to determine the minimum number of operations necessary to make the string displayed on the screen a valid password.

Input

The first line contains two integers nm (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols.

Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase English letters, and characters '#', '*' or '&'.

You have such input data that you can always get a valid password.

Output

Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.

Examples
input
3 4
1**2
a3*0
c4**
output
1
input
5 5
#*&#*
*a1c&
&q2w*
#a3c#
*&#*&
output
3
Note

In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer.

In the second test one of possible algorithms will be:

  • to move the pointer of the second symbol once to the right.
  • to move the pointer of the third symbol twice to the right...

代码:

 #include "cstdio"
 #include "algorithm"
 #include "cstring"
 #include "queue"
 #include "cmath"
 using  namespace std;
 ;
 #define  inf 0x3f3f
 ][];
 ][];//
 int main(){
     int n,m;
     scanf("%d%d",&n,&m);
     ;i<;i++){
         ;j<;j++){
             d[i][j]=;
         }
     }
     ;i<n;i++){
         scanf("%s",s[i]);
     }
 //    memset(d,inf, sizeof(d)); 用inf初始化会溢出导致结果❌卡了好一会
     ;i<n;i++){
         ;j<=m/;j++){
             '){
                 d[i][]=min(d[i][],j);
             }
             if(s[i][j]>='a'&&s[i][j]<='z'){
                 d[i][]=min(d[i][],j);
             }
             if(s[i][j]=='#'||s[i][j]=='*'||s[i][j]=='&'){
                 d[i][]=min(d[i][],j);
             }
             ){
                 ;k<=m/;k++){
                    '){
                        d[i][]=min(d[i][],k);
                    }
                     else if(s[i][m-k]>='a'&&s[i][m-k]<='z'){
                        d[i][]=min(d[i][],k);
                    }
                     ]=min(d[i][],k);}
                 }
             }
         }
     }
     int a,b,c,x=inf;
     ;i<n;i++){
         ;j<n;j++){
             ;k<n;k++){
                 a=min(d[i][]+d[j][]+d[k][],d[i][]+d[k][]+d[j][]);
                 b=min(d[k][]+d[i][]+d[j][],d[k][]+d[j][]+d[i][]);
                 c=min(d[j][]+d[k][]+d[i][],d[j][]+d[i][]+d[k][]);
                 x=min(x,min(min(a,b),c));
             }
         }
     }

     printf("%d\n",x);
     ;
 }

Div.2 C. Dasha and Password的更多相关文章

  1. Codeforces Round #394 (Div. 2) C. Dasha and Password

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力

    C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming ...

  3. Codeforces Round #394 (Div. 2) C. Dasha and Password(简单DP)

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #394 (Div. 2) C. Dasha and Password —— 枚举

    题目链接:http://codeforces.com/problemset/problem/761/C C. Dasha and Password time limit per test 2 seco ...

  5. Codeforces Round #394 (Div. 2) C.Dasha and Password(暴力)

    http://codeforces.com/contest/761/problem/C 题意:给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字 ...

  6. 【枚举】Codeforces Round #394 (Div. 2) C. Dasha and Password

    纪念死去的智商(虽然本来就没有吧……) 三重循环枚举将哪三个fix string作为数字.字母和符号位.记下最小的值就行了. 预处理之后这个做法应该是O(n^3)的,当然完全足够.不预处理是O(n^3 ...

  7. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(分形)

    E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces 761C Dasha and Password(枚举+贪心)

    题目链接 Dasha and Password 题目保证一定有解. 考虑到最多只有两行的指针需要移动,那么直接预处理出该行移动到字母数字或特殊符号的最小花费. 然后O(N^3)枚举求最小值即可. 时间 ...

  9. 【codeforces 761C】Dasha and Password(动态规划做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. webservice中采用协议Http,它是指什么意思

    webservice 协议 Web Service使用的是 SOAP (Simple Object Access Protocol)协议soap协议只是用来封装消息用的.封装后的消息你可以通过各种已有 ...

  2. Pop框架简述

    Facebook发布了Paper之后,进一步开源了其背后的动画引擎Pop,此框架并不满足于苹果自身的动画单调性,致力于给用户一种逼真的动画效果,可以减少用户对于苹果原生Core Animation 复 ...

  3. UILabel的抗压缩、抗拉伸、以及控件的约束简述

    今天来说一说UILabel的约束设置问题 首先主要介绍:Priority(控件约束的优先级).Content Hugging Priority(控件抗拉伸优先级).Content Compressio ...

  4. MySQL 索引的使用

    一.or 的使用 (1)MySQL版本大于 5.x 的会使用 index merge 功能,即可以将多个单列索引集合起来使用,不过在查询时使用 or 的话,引擎为 myisam 的会开启 index ...

  5. 源码解析-knockout源码准备

    准备包括心理和资源两方面. 心理 我看过一句话说,当你用一个框架时,不要忙着看一遍使用教程就开始写项目,先去看看框架原理. 这句话我深以为然.现今前端快速发展,很多前端攻城狮都很茫然:框架更新太快了, ...

  6. EQueue - 一个C#写的开源分布式消息队列的总体介绍(转)

    源: EQueue - 一个C#写的开源分布式消息队列的总体介绍 EQueue - 一个纯C#写的分布式消息队列介绍2 EQueue - 详细谈一下消息持久化以及消息堆积的设计

  7. 网络IO模型

    同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到底有什么区别?这个问题其实不同的人给出 ...

  8. mybatis--常见的错误

    1.没有在configuration.xml配置对应的sql配置文件 错误: Error updating database. Cause: java.lang.IllegalArgumentExce ...

  9. IOS开发-UI学习-NSMutableAttributedString(带属性的字符串)的使用

    带属性的字符串: NSString *aa = @"hellochinaIloveYou!"; NSMutableAttributedString *mas = [[NSMutab ...

  10. web 前端routine

    HTML:check CSS : check Javascript: struggling 框架:—— SQL:—— http://www.cnblogs.com/kzang/tag/SQL/ web ...