This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// In The Name Of God
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl '\n'
#define ioi exit(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = (int)3e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
void add(int &x, int y) {
x += y;
if (x >= mod) x -= mod;
if (x < 0) x += mod;
}
int sum(int x, int y) {
add(x, y);
return x;
}
int mult(int x, int y) {
return x * 1ll * y % mod;
}
struct hashMap {
static const int Sz = 2e4 + 1;
int h[Sz], t[Sz];
hashMap() {
memset(h, 0, sizeof(h));
memset(t, -1, sizeof(t));
}
int add(int x) {
int mask = x % Sz;
while (t[mask] != -1 && t[mask] != x) mask++;
t[mask] = x;
return ++h[mask];
}
} cnt;
int n;
int p[N];
char s[N];
ll ans;
const int p1 = 997;
struct hsh {
int len;
int h[N], dg[N];
void init(char *x) {
len = strlen(x + 1);
dg[0] = 1;
dg[1] = p1;
for (int i = 1; i <= len; i++) {
h[i + 1] = sum(mult(h[i], p1), x[i]);
dg[i + 1] = mult(dg[i], p1);
}
}
ll get(int l, int r) {
return sum(h[r + 1], -mult(h[l], dg[r - l + 1]));
}
} t, t1;
bool check(int l, int r) {
return t.get(l, r) == t1.get(n - r + 1, n - l + 1);
}
ll get(int len) {
int mx = 0;
cnt = hashMap();
for (int i = len; i <= n; i++) {
if (!check(i - len + 1, i)) continue;
mx = max(mx, cnt.add(t.get(i - len + 1, i)));
}
return (ll)mx * len;
}
int main() {
#ifdef IOI2018
freopen ("in.txt", "r", stdin);
//freopen ("slow.out", "w", stdout);
#endif
Kazakhstan
cin >> (s + 1);
n = strlen(s + 1);
t.init(s);
reverse(s + 1, s + 1 + n);
t1.init(s);
reverse(s + 1, s + 1 + n);
for (int i = 1; i <= n; i++) {
ans = max(ans, get(i));
}
cout << ans;
ioi
}
# | 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... |