Flickyyy

B-A'1

Aug 30th, 2022
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include bitsstdc++.h
  2. using namespace std;
  3. #define all(a) a.begin(), a.end()
  4. #define forn(i, a, b, delta) for (ll i = a; i  b; i += delta)
  5. #define FAST ios_basesync_with_stdio(false); cin.tie(nullptr)
  6. using ll = long long;
  7.  
  8. int main() {
  9.     FAST;
  10.     string s;
  11.     cin  s;
  12.     const int n = s.size();
  13.     if (n == 1) {
  14.         cout  1  endl;
  15.         return 0;
  16.     }
  17.     mapchar, int m;
  18.     int cnt_max = 0, max_len = 0;
  19.     for (auto e  s) {
  20.         m[e] += 1;
  21.         cnt_max = max(cnt_max, m[e]);
  22.     }
  23.     for (auto [a, b]  m) {
  24.         if (b == cnt_max) max_len += 1;
  25.     }
  26.     vectorbool inds(n);
  27.     forn(i, 0, n, 1) {
  28.         if (m[s[i]] == cnt_max) {
  29.             inds[i] = true;
  30.         }
  31.     }
  32.     pref zero count
  33.     vectorint zeroes(n + 1);
  34.     forn(i, 1, n + 1, 1) {
  35.         zeroes[i] = zeroes[i - 1];
  36.         if (!inds[i - 1]) zeroes[i] += 1;
  37.     }
  38.  
  39.     ll answer = 1;
  40.     forn(len, 2, max_len + 1, 1) {
  41.         int start_boost = 0;
  42.         while (zeroes[len + start_boost] - zeroes[start_boost] != 0) start_boost += 1;
  43.         forn(boost, 0, len, 1) {
  44.             int equals = 1;
  45.             forn(i, len + boost, s.size() - len + 1, 1) {
  46.                 forn(j, boost, len + boost, 1) cout  s[j];
  47.                 cout    ;
  48.                 forn(j, i, i + len, 1) cout  s[j];
  49.                 cout  endl;
  50.                 is [boost; len + boost - 1] and [i; i + len - 1] are the row substrings
  51.                 int z1 = zeroes[len + boost] - zeroes[boost], z2 = zeroes[i + len] - zeroes[i];
  52.                 if (z1 + z2  0) {
  53.                     cout  skippedn;
  54.                     continue;
  55.                 }
  56.                 is [boost; len + boost - 1] equals to [i; i + len - 1]
  57.                 if (string(s.begin() + boost, s.begin() + len + boost) == string(s.begin() + i, s.begin() + i + len)) {
  58.                     equals += 1;
  59.                     i += len- 1;
  60.                 }
  61.  
  62.             }
  63.             if (equals == cnt_max) {
  64.                 answer = max(answer, len);
  65.             }
  66.         }
  67.     }
  68.  
  69.     cout  max_len   max_len  endl;
  70.     cout  cnt_max   cnt_max  endl;
  71.     cout  answer  endl;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment