# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
549963 | Duy_e | Palindromes (APIO14_palindrome) | C++14 | 2 ms | 340 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.
/*
** TASK:
** LINK:
*/
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long INF = 1e18;
const long long N = 2e5 + 5;
const long long base = 311;
const long long MOD = 1e9 + 321;
string s;
ll h[N], ph[N], pw[N], n;
ll get(int l, int r) {
return (h[r] - h[l - 1] * pw[r - l + 1] % MOD + MOD * MOD) % MOD;
}
ll getpre(int l, int r) {
return (ph[l] - ph[r + 1] * pw[r - l + 1] % MOD + MOD * MOD) % MOD;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
#endif
cin >> s;
s = '#' + s;
n = s.size() - 1;
pw[0] = 1;
for (int i = 1; i <= n; i ++) {
pw[i] = pw[i - 1] * base % MOD;
h[i] = (h[i - 1] * base + s[i]) % MOD;
}
for (int i = n; i >= 1; i --)
ph[i] = (ph[i + 1] * base + s[i]) % MOD;
map <int, ll> dp;
ll ans = 0;
for (int i = 1; i <= n; i ++)
for (int j = i; j <= n; j ++) {
ll x = get(i, j);
if (x == getpre(i, j)) {
// cout << i << ' ' << j << '\n';
dp[x] += j - i + 1;
ans = max(ans, dp[x]);
}
}
cout << ans;
return 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... |