# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
955473 | hoanganh_siuuuuuuuu | Palindromes (APIO14_palindrome) | C++17 | 1059 ms | 6672 KiB |
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 int long long
#define f(i, a, b) for(int i = a; i <= b; i++)
#define fr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define in insert
#define vvec vector<vector<int>>
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
const int base = 31;
int n, Hash[N], Pow[N];
unordered_map <int, int> mp;
string s;
int get(int i, int j)
{
return (Hash[j] - Hash[i - 1] * Pow[j - i + 1] + mod * mod) % mod;
}
void sub2()
{
int res = 0;
f(i, 1, n)
{
int t = 0;
while(i - t >= 1 && i + t <= n && s[i - t] == s[i + t])
{
int z = ++mp[get(i - t, i + t)];
// cout << get(i - t, i + t) << "\n";
//cout << i << " " << z << " " << (2 * t + 1) << "\n";
res = max(res, (2 * t + 1) * z);
t++;
}
t = 0; int j = i + 1;
while(i - t >= 1 && j + t <= n && s[i - t] == s[j + t])
{
int z = ++mp[get(i - t, j + t)];
//cout << get(i - t, j + t) << "\n";
//cout << i << " " << z << " " << (2 * t + 2) << "\n";
res = max(res, (2 * t + 2) * z);
t++;
}
}
cout << res;
}
signed main()
{
fast;
if(fopen("palindrome.in", "r"))
{
freopen("palindrome.in", "r", stdin);
freopen("palindrome.out", "w", stdout);
}
cin >> s;
n = s.size(); s = '!' + s;
Pow[0] = 1;
f(i, 1, n)
{
//a[i] = s[i] - 'a';
Hash[i] = (Hash[i - 1] * base + (s[i] - 'a' + 1)) % mod;
Pow[i] = (Pow[i - 1] * base) % mod;
}
sub2();
//int l = 0,
}
Compilation message (stderr)
# | 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... |