fork download
  1. #include <string>
  2. #include <vector>
  3. #include <iostream>
  4. #include <algorithm>
  5. #define ull unsigned long long
  6. using namespace std;
  7. string s; vector<pair<ull, int> > v;
  8. int main() {
  9. cin >> s;
  10. for(int i = 0; i < s.size(); i++) {
  11. ull t = 0;
  12. for(int j = i; j < s.size(); j++) {
  13. t = t * 257 + s[j];
  14. v.push_back(make_pair(t, j - i + 1));
  15. }
  16. }
  17. sort(v.begin(), v.end());
  18. long long ret = v[0].second;
  19. for(int i = 1; i < v.size(); i++) {
  20. if(v[i].first != v[i - 1].first) {
  21. ret += v[i].second;
  22. }
  23. }
  24. printf("%lld\n", ret);
  25. }
Success #stdin #stdout 0s 3468KB
stdin
abracadabra
stdout
264