Advertisement
tanasaradu

Untitled

Dec 30th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int Nmax = 2005;
  4. char s[Nmax];
  5. int a[Nmax][Nmax] , aux[Nmax][Nmax] , n;
  6. inline bool CHECK(int i , int j)
  7. {
  8. while(i <= j)
  9. {
  10. if(s[i] != s[j])
  11. return false;
  12. i++;
  13. j--;
  14. }
  15. return true;
  16. }
  17. int main()
  18. {
  19. int x , y , xx , yy;
  20. long long sol = 0;
  21. cin >> (s+1);
  22. n = strlen(s+1);
  23. for(int i = 1 ; i <= n ; i++)
  24. for(int j = i ; j <= n ; j++)
  25. a[i][j] = aux[i][j] = CHECK(i , j);
  26. for(int i = 1 ; i <= n ; i++)
  27. for(int j = 1 ; j <= n ; j++)
  28. a[i][j] = a[i][j] + a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
  29. for(int i = 1 ; i <= n ; i++)
  30. for(int j = 1 ; j <= n ; j++)
  31. if(aux[i][j] == 1)
  32. {
  33. x = max(i , j) + 1;
  34. y = max(i , j) + 1;
  35. xx = n;
  36. yy = n;
  37. sol += a[xx][yy] - a[x - 1][yy] - a[xx][y - 1] + a[x - 1][y - 1];
  38. }
  39. cout << sol << "\n";
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement