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>
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const ll p = 29;
const ll P1 = 1000000007;
const ll P2 = 1000000009;
const int MAX_N = 300000;
int N;
string str;
vector<pll> vt[MAX_N+1];
ll ans = 0;
int main(){
cin>>str;
N = str.size();
for(int i=0; i<N; i++){
pll now = {str[i]-'a'+1, str[i]-'a'+1};
ll m1=p, m2=p;
pll now2 = {str[i]-'a'+1, str[i]-'a'+1};
vt[1].pb(now);
for(int j=i+1; j<N; j++){
now.first = (now.first * p + str[j]-'a' + 1) % P1;
now.second = (now.second * p + str[j]-'a'+1) % P2;
now2.first = (now2.first + m1 * (ll)(str[j]-'a'+1)) % P1;
now2.second = (now2.second + m2 * (ll)(str[j]-'a'+1)) % P2;
m1 = (m1 * p) % P1; m2 = (m2 * p) % P2;
if(now.first==now2.first && now.second==now2.second) vt[j-i+1].pb(now);
}
}
for(int i=1; i<=N; i++){
sort(vt[i].begin(), vt[i].end());
int s = 0, e = 0;
while(s<vt[i].size()){
while(e<vt[i].size()-1 && vt[i][s].first==vt[i][e+1].first && vt[i][s].second==vt[i][e+1].second){
e++;
}
ans = max(ans, (ll)(e-s+1) * (ll)i);
s = e+1; e++;
}
}
cout<<ans;
return 0;
}
Compilation message (stderr)
palindrome.cpp: In function 'int main()':
palindrome.cpp:56:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(s<vt[i].size()){
~^~~~~~~~~~~~~
palindrome.cpp:57:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(e<vt[i].size()-1 && vt[i][s].first==vt[i][e+1].first && vt[i][s].second==vt[i][e+1].second){
~^~~~~~~~~~~~~~~
# | 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... |