이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 300'000 + 10;
string s;
int n;
struct Hash {
int base, M;
vector<int> h, rh, pw;
Hash() : base(0), M(0) {}
Hash(string s, int base, int M) : base(base), M(M), h(s.size() + 1), rh(s.size() + 1), pw(s.size() + 1) {
pw[0] = 1;
for (int i = 1; i <= n; ++i) {
pw[i] = 1ll * pw[i - 1] * base % M;
h[i] = (1ll * h[i - 1] * base % M + s[i - 1]) % M;
rh[i] = (1ll * rh[i - 1] * base % M + s[n - i]) % M;
}
}
int get(int l, int r) {
return (h[r] - 1ll * h[l - 1] * pw[r - l + 1] % M + M) % M;
}
int rget(int l, int r) {
return (rh[r] - 1ll * rh[l - 1] * pw[r - l + 1] % M + M) % M;
}
} T[2];
using HASH = pair<int, int>;
inline HASH get(int l, int r) {
return make_pair(T[0].get(l, r), T[1].get(l, r));
}
inline HASH rget(int l, int r) {
tie(l, r) = make_pair(n - r + 1, n - l + 1);
return make_pair(T[0].rget(l, r), T[1].rget(l, r));
}
bool chk(int l, int r) { return get(l, r) == rget(l, r); }
map<HASH, long long> cnt;
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> s;
n = s.size();
T[0] = Hash(s, 19937, 1e9 + 7);
T[1] = Hash(s, 10007, 1e9 + 9);
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) if (chk(i, j)) cnt[get(i, j)] += j - i + 1;
}
long long answer = 0;
for (const auto& x : cnt) answer = max(answer, x.second);
cout << answer << "\n";
}
# | 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... |