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;
bool pal(string a) {
int l = 0, r = a.size() - 1;
while (l < r) {
if (a[l] != a[r])
return false;
l++, r--;
}
return true;
}
int occ(string a, string s){
int n = (int)s.size();
int k = (int)a.size();
string window = "";
int ret = 0;
for(int i = 0; i < k; ++i)
window += s[i];
if(window == a)
ret++;
// time complexity if erase is O(n + m)
for(int i = k; i < n; ++i){
window += s[i];
window.erase(0, 1);
if(window == a)
ret++;
}
return ret;
}
int main(){
string s;
cin >> s;
int n = (int)s.size();
int mx = INT_MIN;
for (int i = 0; i < n; ++i)
for (int j = 1; j <= n - i; ++j) {
string a = s.substr(i, j);
if (pal(a)){
int ret = a.size() * occ(a, s);
mx = max(mx, ret);
}
}
cout << mx << "\n";
return 0;
}
# | 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... |