fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. #define fast_io \
  6.   ios_base::sync_with_stdio(false); \
  7.   cin.tie(NULL); \
  8.   cout.tie(NULL)
  9. #define nl << "\n"
  10.  
  11. int count_cost(string s)
  12. {
  13. int ans=0;
  14. for(int i=0; i<s.size(); i++)
  15. {
  16. int a=s[i]-'a';
  17. a++;
  18. ans+=a;
  19. }
  20. return ans;
  21. }
  22.  
  23. void solve() {
  24. int n,k;
  25. cin>>n;
  26. k=15;
  27. int ans=0;
  28. while(n--)
  29. {
  30. string s;
  31. cin>>s;
  32. int a=s.size();
  33. s+=s;
  34. string sel="zzzzzzzzzzzzzzz";
  35. for(int i=0; i<a; i++)
  36. {
  37. string s1="";
  38. for(int j=0; j<k; j++)
  39. s1.push_back(s[j+i]);
  40. if(sel>s1)
  41. sel=s1;
  42. }
  43. ans+=count_cost(sel);
  44. }
  45. cout<<ans nl;
  46. }
  47.  
  48. int32_t main() {
  49. fast_io;
  50. solve();
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0.01s 5440KB
stdin
2
aaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaagggggggg
stdout
30