Advertisement
arif334

hr-short-palindrome

Nov 25th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. /**
  2.     * Author    : Arif Ahmad
  3.     * Date      :
  4.     * Algo      :
  5.     * Difficulty:
  6. */
  7.  
  8. #include <bits/stdc++.h>
  9. using namespace std;
  10.  
  11. #define INF_MAX     2147483647
  12. #define INF_MIN     -2147483648
  13. #define INF         (1 << 30)
  14. #define EPS         1e-9
  15. #define PI          acos(-1.0)
  16. #define N           2 + 1000000
  17. #define MOD         1000000007
  18. #define sz(x)       (int)(x).size()
  19. #define all(x)      (x).begin(), (x).end()
  20. #define pb          push_back
  21. #define mp          make_pair
  22. #define ms(x, a)    memset((x), (a), sizeof(x))
  23. #define F           first
  24. #define S           second
  25. #define rep(i,a,b)  for(int i=(a); i<(b); ++i)
  26. #define repC(i,x)   for(size_t i=0; i<x.size(); ++i)
  27. #define repIT(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
  28. #define nn          '\n'
  29.  
  30. typedef long long       LL;
  31. typedef pair<int,int>   pii;
  32. typedef vector<int>     vi;
  33. typedef vector<string>  vs;
  34. typedef vector<char>    vc;
  35. typedef vector<bool>    vb;
  36. typedef vector< pii >   vii;
  37. typedef map<string,int> msi;
  38. typedef map<int,int>    mii;
  39. typedef map<char,int>   mci;
  40. typedef map<int,string> mis;
  41.  
  42. template<class T> T Abs(T x) {return x>0 ? x : -x;}
  43. template<class T> T Max(T a, T b) {return a>b ? a : b;}
  44. template<class T> T Min(T a, T b) {return a<b ? a : b;}
  45. template<class T> T gcd(T a, T b) {return (b ? gcd(b,a%b) : a);}
  46. bool isVowel(char ch){ch=tolower(ch);return(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u');}
  47.  
  48. //int dx[4] = {-1, 0, 0, 1};
  49. //int dy[4] = {0, -1, 1, 0};
  50. //int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  51. //int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  52.  
  53. int main()
  54. {
  55.     ios_base :: sync_with_stdio(0);
  56.     cin.tie(0);
  57.  
  58.     #ifndef ONLINE_JUDGE
  59.         /// comment it out before submission
  60.         //freopen("in.txt", "r", stdin);
  61.     #endif
  62.  
  63.     int i, j, k, n, tc;
  64.     string s;
  65.     int freq[26] = {0};
  66.     int pair_freq[26][26] = {0};
  67.     int triplet_freq[26] = {0};
  68.     int ans = 0;
  69.  
  70.     cin >> s;
  71.     for(char c : s) {
  72.         int v = int(c - 'a');
  73.         ans = (ans + triplet_freq[v]) % MOD;
  74.  
  75.         for(int i=0; i<26; i++) {
  76.             triplet_freq[i] = (triplet_freq[i] + pair_freq[i][v]) % MOD;
  77.         }
  78.  
  79.         for(int i=0; i<26; i++) {
  80.             pair_freq[i][v] = (pair_freq[i][v] + freq[i]) % MOD;
  81.         }
  82.  
  83.         freq[v]++;
  84.     }
  85.  
  86.     cout << ans << '\n';
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement