题目链接:http://codeforces.com/problemset/problem/761/C点击打开链接
#include <bits/stdc++.h>
using namespace std;
vector<string >s;
int main()
{
int n,m;
cin >> n>>m;
for(int i=0;i<n;i++)
{
string mid;
cin >> mid;
s.push_back(mid);
}
int cnt[3][n];
for(int i=0;i<n;i++)
{
cnt[0][i]=cnt[1][i]=cnt[2][i]=m;
for(int j=0;j<m;j++)
{
int jmid=min(j,m-j);
if(isdigit(s[i][j]))
cnt[0][i]=min(cnt[0][i],jmid);
else if('a'<=s[i][j]&&s[i][j]<='z')
cnt[1][i]=min(cnt[1][i],jmid);
else
cnt[2][i]=min(cnt[2][i],jmid);
}
}
int ans=3*m;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
for(int k=0;k<n;k++)
{
if(i==j||j==k||k==i)
continue;
ans=min(ans,cnt[0][i]+cnt[1][j]+cnt[2][k]);
ans=min(ans,cnt[0][i]+cnt[2][j]+cnt[1][k]);
ans=min(ans,cnt[1][i]+cnt[0][j]+cnt[2][k]);
ans=min(ans,cnt[1][i]+cnt[2][j]+cnt[0][k]);
ans=min(ans,cnt[2][i]+cnt[0][j]+cnt[1][k]);
ans=min(ans,cnt[2][i]+cnt[1][j]+cnt[0][k]);
}
}
}
cout << ans << endl;
}