fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define el "\n"
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define se second
  7. #define fi first
  8. #define be begin()
  9. #define en end()
  10. #define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
  11.  
  12. int main()
  13. {
  14. Faster;
  15. string s; cin >> s;
  16. int ans = 0;
  17. for(int i = 0; i < s.size(); i++)
  18. {
  19. if(s.size() - i - 1 < ans) break;
  20. unordered_map<char,int> mp;
  21. for(int j = i; j < s.size();j++)
  22. {
  23. mp[s[j]]++;
  24. int tmp = mp[s[i]], ok = 1;
  25. for(pair<char,int> x : mp)
  26. {
  27. if(x.se != tmp)
  28. {
  29. ok = 0;
  30. break;
  31. }
  32. }
  33. if(ok == 1) ans = max(ans, j - i + 1);
  34. }
  35. }
  36. cout << ans;
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 5272KB
stdin
aabbccd
stdout
6