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. //cout<<"Cost of string "<<s<<" is -> "<<ans nl;
  21. return ans;
  22. }
  23.  
  24. void solve() {
  25. int n,k;
  26. cin>>n;
  27. k=15;
  28. int ans=0;
  29. while(n--)
  30. {
  31. string s;
  32. cin>>s;
  33. int a=s.size();
  34. s+=s;
  35. string sel="zzzzzzzzzzzzzzz";
  36. for(int i=0;i<a;i++)
  37. {
  38. string s1;
  39. s1=s.substr(i,k);
  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 5336KB
stdin
2
aaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaagggggggg
stdout
30