Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include bitsstdc++.h
- using namespace std;
- #define all(a) a.begin(), a.end()
- #define forn(i, a, b, delta) for (ll i = a; i b; i += delta)
- #define FAST ios_basesync_with_stdio(false); cin.tie(nullptr)
- using ll = long long;
- int main() {
- FAST;
- string s;
- cin s;
- const int n = s.size();
- if (n == 1) {
- cout 1 endl;
- return 0;
- }
- mapchar, int m;
- int cnt_max = 0, max_len = 0;
- for (auto e s) {
- m[e] += 1;
- cnt_max = max(cnt_max, m[e]);
- }
- for (auto [a, b] m) {
- if (b == cnt_max) max_len += 1;
- }
- vectorbool inds(n);
- forn(i, 0, n, 1) {
- if (m[s[i]] == cnt_max) {
- inds[i] = true;
- }
- }
- pref zero count
- vectorint zeroes(n + 1);
- forn(i, 1, n + 1, 1) {
- zeroes[i] = zeroes[i - 1];
- if (!inds[i - 1]) zeroes[i] += 1;
- }
- ll answer = 1;
- forn(len, 2, max_len + 1, 1) {
- int start_boost = 0;
- while (zeroes[len + start_boost] - zeroes[start_boost] != 0) start_boost += 1;
- forn(boost, 0, len, 1) {
- int equals = 1;
- forn(i, len + boost, s.size() - len + 1, 1) {
- forn(j, boost, len + boost, 1) cout s[j];
- cout ;
- forn(j, i, i + len, 1) cout s[j];
- cout endl;
- is [boost; len + boost - 1] and [i; i + len - 1] are the row substrings
- int z1 = zeroes[len + boost] - zeroes[boost], z2 = zeroes[i + len] - zeroes[i];
- if (z1 + z2 0) {
- cout skippedn;
- continue;
- }
- is [boost; len + boost - 1] equals to [i; i + len - 1]
- if (string(s.begin() + boost, s.begin() + len + boost) == string(s.begin() + i, s.begin() + i + len)) {
- equals += 1;
- i += len- 1;
- }
- }
- if (equals == cnt_max) {
- answer = max(answer, len);
- }
- }
- }
- cout max_len max_len endl;
- cout cnt_max cnt_max endl;
- cout answer endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment