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 F first
#define S second
#define pb push_back
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
const int N = 10000 + 5;
const int mod = 8815211;
bool dp[N][N];
string s;
int n, P[N], H[N];
int mp[mod + 5];
int Hash(int l, int r)
{
return (H[r] - 1ll * H[l - 1] * P[r - l + 1] + 1ll * mod * mod) % mod;
}
void build()
{
for(int i = 1; i <= n; i++)
H[i] = (1ll * H[i - 1] * P[1] + (s[i] - 'a' + 1)) % mod;
}
void solve()
{
cin >> s;
n = s.size();
s = " " + s;
P[1] = 431;
for(int i = 2; i <= n; i++)
P[i] = 1ll * P[i - 1] * P[1] % mod;
build();
int res = 0;
for(int j = 1; j <= n; j++)
for(int i = j; i >= 1; i--)
{
if(s[i] == s[j])
dp[i][j] = (i == j || i + 1 == j || dp[i + 1][j - 1]);
res = max(res, ++mp[Hash(i, j)] * (j - i + 1));
}
cout << res;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--) solve();
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... |