Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <map>
- #include <vector>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- #include <stdio.h>
- #include <queue>
- #include <cstdio>
- #include <stack>
- #include <iomanip>
- #include <numeric>
- #include <fstream>
- #include <functional>
- #include <sstream>
- #define SSTR( x ) dynamic_cast< std::ostringstream & >( \
- ( std::ostringstream() << std::dec << x ) ).str()
- #define LL long long
- #define fr(i,j) for(int i=0; i<j; i++)
- #define each(i,in,j) for(int i=in; i<j; i++)
- #define F first
- #define S second
- using namespace std;
- ifstream fin("strings.in");
- #define cin fin
- ofstream fout("strings.out");
- #define cout fout
- const int con = 1e9;
- typedef vector<int> vi;
- typedef vector<vector<int > > vvi;
- typedef vector<pair<int,int > > vpi;
- typedef pair<int, int> pi;
- typedef vector<int>::iterator viit;
- typedef vector<LL> vll;
- typedef vector<bool> vb;
- template <typename T>
- void gv (vector<T>& a){
- fr(h,a.size()) scanf("%d",&a[h]);
- }
- void gv (vpi& a){
- int b,c;
- fr(h,a.size()) {
- scanf("%d %d",&b,&c);
- a[h].first = b;
- a[h].second = c;
- }
- }
- int max(int a, int b) {
- return a>b?a:b;
- }
- void pnt (vi a, int n) {
- fr(h,n) cout<<a[h]<<" ";
- cout<<"\n";
- }
- template <typename T>
- void pnt (vector<T> a) {
- if (a.size()==0) cout<<"\n";
- fr(h,a.size()-1) cout<<a[h]<<" ";
- cout<<a.back()<<"\n";
- }
- void pnt (vvi a) {
- fr(h,a.size()) pnt(a[h]);
- }
- int gcd (int a, int b) {
- return b ? gcd (b, a % b) : a;
- }
- vpi v;
- bool cond (int i, int j){
- pi p1 = v[i], p2 = v[j];
- return (p1.F<p2.F)||(p1.F==p2.F&&p1.S<=p2.S);
- }
- map<string, int> m;
- vi oc;
- int mx;
- string ans;
- string s;
- int n;
- void proc(int l){
- bool b;
- for(int i = 0; i <= n-l; i++){
- b = true;
- int lim = i+l;
- for(int j = i; j<i+l; j++){
- if (oc[j]<lim) b = false;
- }
- if (b) {
- string t = s.substr(i,l);
- m[t]++;
- if (m[t]>=mx) mx = m[t], ans = t;
- }
- }
- }
- int main()
- {
- cin>>s;
- n = s.size();
- oc.resize(n, n+1);
- map<char, int> oc2;
- fr(i,n){
- if (oc2.find(s[i])!=oc2.end()) oc[oc2[s[i]]] = i;
- oc2[s[i]] = i;
- }
- oc2.clear();
- fr(i,n){
- oc2[s[i]]++;
- if (oc2[s[i]]>mx) {
- mx = oc2[s[i]];
- ans = s.substr(i,1);
- }
- }
- int l = 1;
- int r = 27;
- while(l<r-1){
- m.clear();
- int mid = l + (r-l)/2;
- string t = ans;
- proc(mid);
- if (t!=ans) l = mid;
- else r = mid;
- }
- cout<<ans.size()<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement