Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <string>
- #include <cstring>
- #include <map>
- #include <cmath>
- #include <set>
- #include <vector>
- using namespace std;
- #define forit(it, s) for(typeof(s.begin()) it = s.begin(); it != s.end(); it++)
- #define pb push_back
- #define MP make_pair
- #define F first
- #define S second
- #define sz size()
- #define LL long long
- #define TASK "strings"
- const int inf = (1<<30);
- const int maxn = int(1e5) + 123;
- const int mod = int(1e9) + 7;
- string s;
- int cnt[30];
- int ans = 1, mx;
- set < int > q;
- vector < int > pos[30];
- int main () {
- freopen(TASK".in", "r", stdin);
- freopen(TASK".out", "w", stdout);
- cin >> s;
- for (int i = 0; i < s.sz; i++)
- cnt[s[i] - 'a'] ++;
- for (int i = 0; i < 26; i++)
- mx = max(mx, cnt[i]);
- for (int i = 0; i < s.sz; i++)
- pos[s[i] - 'a'].pb(i);
- for (int i = 0; i < 26; i++)
- if (cnt[i] == mx)
- q.insert(i);
- if (mx == 1) {
- cout << s.sz;
- return 0;
- }
- forit(it, q) {
- int k = (*it);
- char sym = char(k + 'a');
- int len = inf;
- for (int i = 1; i < pos[k].sz; i++) {
- len = min(len, pos[k][i] - pos[k][i - 1]);
- }
- int l;
- for (l = 1; l <= len; l++) {
- set < char > cur;
- for (int i = 0; i < pos[k].sz; i++)
- cur.insert(s[pos[k][i] + l - 1]);
- if (cur.sz != 1) break;
- }
- ans = max(ans, l - 1);
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement