# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676328 | vuavisao | Palindromes (APIO14_palindrome) | C++14 | 1082 ms | 988 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>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
using namespace std;
template<typename Lhs, typename Rhs> inline bool Max_self(Lhs &a, Rhs b) { if(b > a) { a = b; return true; } return false; }
template<typename Lhs, typename Rhs> inline bool Min_self(Lhs &a, Rhs b) { if(b < a) { a = b; return true; } return false; }
const int N = 3e5 + 10;
int n;
string s;
namespace sub123 {
bool check() {
return n <= 10000;
}
const int BASE = 128;
const int MOD = 1e9 + 7;
int p[N], h[N], h_rev[N];
int res;
int get_hash(int l, int r, int* h) {
return (h[r] - 1ll * h[l - 1] * p[r - l + 1] % MOD + MOD) % MOD;
}
void solve() {
p[0] = 1;
for(int i = 1; i <= n; ++ i) {
p[i] = 1ll * p[i - 1] * BASE % MOD;
h[i] = (1ll * h[i - 1] * BASE + s[i]) % MOD;
h_rev[i] = (1ll * h_rev[i - 1] * BASE + s[n - i + 1]) % MOD;
}
for(int len = 1; len <= n; ++ len) {
unordered_map<int, int> mpp;
auto palin = [&] (int l, int r) -> bool {
return get_hash(l, r, h) == get_hash(n - r + 1, n - l + 1, h_rev);
};
for(int i = 1; i <= n - len + 1; ++ i) {
if(palin(i, i + len - 1)) {
int hash = get_hash(i, i + len - 1, h);
++ mpp[hash];
Max_self(res, mpp[hash] * len);
}
}
}
cout << res;
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("APIO14_palindrome.inp", "r")) {
freopen("APIO14_palindrome.inp", "r", stdin);
freopen("APIO14_palindrome.out", "w", stdout);
}
cin >> s; n = (int) s.size(); s = ' ' + s;
if(sub123::check()) {
sub123::solve();
return 0;
}
return 0;
}
/// Code by vuavisao
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... |