Advertisement
hung_mine

SEPARATE

Oct 11th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. /// from HUNG MINE with love <3
  4. const long long MOD = 1337377;
  5. int t[400001][50], n, m, e[400001], cc = 0;
  6. long long f[300001];
  7. string s, a;
  8. int main () {
  9.       if (fopen ("test.inp", "r")) {
  10.             freopen ("test.inp", "r", stdin);
  11.       }
  12. //      else {
  13. //            freopen ("SEPARATE.inp", "r", stdin);
  14. //            freopen ("SEPARATE.out", "w", stdout);
  15. //      }
  16.  
  17.       ios_base :: sync_with_stdio (0);
  18.       cin.tie (0);
  19.       cout.tie (0);
  20.       cin >> s;
  21.       n = s.size ();
  22.       s = '@' + s;
  23.       cin >> m;
  24.       for (int i = 1; i <= m; ++ i) {
  25.             cin >> a;
  26.             int r = 0;
  27.             for (int j = a.size () - 1; j >= 0; -- j) {
  28.                   if (t[r][a[j] - 'a'] == 0) {
  29.                         t[r][a[j] - 'a'] = ++ cc;
  30.                   }
  31.                   r = t[r][a[j] - 'a'];
  32.             }
  33.             e[r] = 1;
  34.       }
  35.       f[0] = 1;
  36.       for (int i = 1; i <= n; ++ i) {
  37.             int r = 0;
  38.             for (int j = i; j >= 1; -- j) {
  39.                   if (t[r][s[j] - 'a'] == 0) break;
  40.                   r = t[r][s[j] - 'a'];
  41.                   if (e[r]) {
  42.                         f[i] += f[j - 1];
  43.                         f[i] %= MOD;
  44.                   }
  45.             }
  46.       }
  47.       cout << f[n];
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement