fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <queue>
  4. #include <stack>
  5. #include <vector>
  6. #include <climits>
  7. #include <map>
  8. #include <set>
  9. #include <cassert>
  10. #include <cstdio>
  11. #include <cstring>
  12. #include <cmath>
  13. #include <deque>
  14. #include <string>
  15. #include <sstream>
  16. #include <cstdlib>
  17. #include <unordered_set>
  18. #include <unordered_map>
  19.  
  20. using namespace std;
  21.  
  22. string v[55];
  23. int dp[55][2][2][2];
  24. int n,m;
  25. int f(int pos, bool vw, bool dg, bool sb){
  26. if(pos == n){
  27. if(vw+dg+sb == 3) return 0;
  28. else return 1e9;
  29. }
  30.  
  31. if(dp[pos][vw][dg][sb] != -1) return dp[pos][vw][dg][sb];
  32. int ans = 1e9;
  33. for (int i = 0; i < (int)v[pos].size(); ++i){
  34. string x = v[pos];
  35. int sz = x.size();
  36. if(x[i]-'a' >= 0 and x[i]-'a'<= 27) ans = min(ans,f(pos+1,true,dg,sb)+min(i,sz-i));
  37. if(isdigit(x[i])) ans = min(ans,f(pos+1,vw,true,sb)+min(i,sz-i));
  38. if(x[i] == '#' or x[i] == '*' or x[i] == '&')
  39. ans = min(ans,f(pos+1,vw,dg,true)+min(i,sz-i));
  40. }
  41. return dp[pos][vw][dg][sb] = ans;
  42. }
  43. int main(){
  44. memset(dp,-1,sizeof dp);
  45. cin >> n >> m;
  46. for (int i = 0; i < n; ++i) cin >> v[i];
  47. cout << f(0,0,0,0) << "\n";
  48. return 0;
  49. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
1000000000