fork(4) download
  1. // @author cthulhuhluhtc
  2. #include <bits/stdc++.h>
  3.  
  4. #pragma GCC optimize("Ofast")
  5. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. #pragma GCC optimize("no-stack-protector,unroll-loops")
  7. #pragma GCC diagnostic ignored "-Wunused-result"
  8. #pragma GCC diagnostic ignored "-Wunused-function"
  9.  
  10. #define _CRT_SECURE_NO_WARNINGS
  11.  
  12. #define mp make_pair
  13. #define mt make_tuple
  14. #define pb push_back
  15. #define eb emplace_back
  16. #define F first
  17. #define S second
  18. #define sz(x) ((int)(x).size())
  19. #define all(x) (x).begin(), (x).end()
  20.  
  21. #define forn(i, n) for (int i = 0; i < (int)(n); i++)
  22. #define range(i, low, high) for (int i = (low); i < (high); i++)
  23. #define rrange(i, low, high) for (int i = (high) - 1; i >= (low); i--)
  24.  
  25. #define checkbit(n, b) (((n) >> (b)) & 1)
  26. #define setbit(n, b) ((n) | (static_cast<decay_t<decltype(n)>>(1) << (b)))
  27. #define removebit(n, b) ((n) & ~(static_cast<decay_t<decltype(n)>>(1) << (b)))
  28. #define flipbit(n, b) ((n) ^ (static_cast<decay_t<decltype(n)>>(1) << (b)))
  29.  
  30. #define ri(x) cin >> x
  31. #define dri(x) int x; cin >> x
  32. #define rii(x, y) cin >> x >> y
  33. #define drii(x, y) int x, y; cin >> x >> y
  34. #define riii(x, y, z) cin >> x >> y >> z
  35. #define driii(x, y, z) int x, y, z; cin >> x >> y >> z
  36.  
  37. #define ms0(x) memset(x, 0, sizeof(x))
  38. #define ms1(x) memset(x, -1, sizeof(x))
  39.  
  40. using namespace std;
  41.  
  42. typedef double db;
  43. typedef long double ld;
  44. typedef long long ll;
  45. typedef unsigned long long ull;
  46.  
  47. typedef vector<int> vi;
  48. typedef pair<int, int> pii;
  49. typedef vector<vi> vvi;
  50. typedef vector<pii> vpi;
  51.  
  52.  
  53.  
  54.  
  55. ll dp[51][51][51][51];
  56. vector<int> p[4][26];
  57. void solve() {
  58. int n = 4;
  59. forn(i, n) {
  60. string s; cin >> s;
  61. forn(j, sz(s)) p[i][s[j] - 'a'].eb(j);
  62. }
  63. forn(i, 26) {
  64. if (p[0][i].empty() || p[1][i].empty() || p[2][i].empty() || p[3][i].empty())
  65. continue;
  66. dp[p[0][i][0]][p[1][i][0]][p[2][i][0]][p[3][i][0]] = 1;
  67. }
  68. forn(i0, 51) forn(i1, 51) forn(i2, 51) forn(i3, 51) {
  69. if (!dp[i0][i1][i2][i3]) continue;
  70. forn(i, 26) {
  71. auto t0 = upper_bound(all(p[0][i]), i0);
  72. auto t1 = upper_bound(all(p[1][i]), i1);
  73. auto t2 = upper_bound(all(p[2][i]), i2);
  74. auto t3 = upper_bound(all(p[3][i]), i3);
  75. if (t0 == p[0][i].end() || t1 == p[1][i].end() || t2 == p[2][i].end() || t3 == p[3][i].end()) continue;
  76. dp[*t0][*t1][*t2][*t3] += dp[i0][i1][i2][i3];
  77. }
  78. }
  79. ll ans = 0;
  80. forn(i0, 51) forn(i1, 51) forn(i2, 51) forn(i3, 51) ans += dp[i0][i1][i2][i3];
  81. cout << ans << "\n";
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. int main(int argc, char** argv) {
  92. ios_base::sync_with_stdio(0); cin.tie(0);
  93. cout.precision(20); cout << fixed;
  94. clock_t clock_start = clock();
  95. //freopen("a.in", "r", stdin);
  96. //freopen("a.out", "w", stdout);
  97. //freopen("input.txt", "r", stdin);
  98. //freopen("output.txt", "w", stdout);
  99. solve();
  100. //cout << "Time elapsed: " << (ld)(clock() - clock_start) / CLOCKS_PER_SEC << "\n";
  101. return 0;
  102. }
  103.  
  104.  
Success #stdin #stdout 0.03s 4196KB
stdin
Standard input is empty
stdout
0