This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
#define int long long
bool chmin(int &x, int y){
bool flag = false;
if ( x > y ){
x = y; flag |= true;
}
return flag;
}
bool chmax(int &x, int y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string s; cin >> s;
int n = (int)s.size();
map <string,int> mp;
for ( int i = 0; i < n; i++ ){
string c;
for ( int j = i; j < n; j++ ){
c += s[j];
++mp[c];
}
}
int Mx = 0;
for ( int i = 0; i < n; i++ ){
string l, r;
l += s[i];
chmax(Mx, mp[l + r]);
for ( int j = i - 1; j >= 0; j-- ){
if ( (i - j) + i >= n ) break;
if ( s[j] != s[i + (i - j)] )break;
l = s[j] + l; r += s[j];
chmax(Mx, mp[l + r] * ((i - j) * 2 + 1));
}
if ( i + 1 == n or s[i + 1] != s[i] ) continue;
l = r = "";
l += s[i], r += s[i];
chmax(Mx, mp[l + r] * 2);
for ( int j = i - 1; j >= 0; j-- ){
if ( (i - j) + (i + 1) >= n ) break;
if ( s[j] != s[i + 1 + (i - j)] ) break;
l = s[j] + l; r += s[j];
chmax(Mx, mp[l + r] * (i - j + 1) * 2);
}
}
cout << Mx;
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |