이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/// 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;
}
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;
unordered_map <int, int> cnt;
for (int i = len; i <= n; i++) {
if (!check(i - len + 1, i)) continue;
mx = max(mx, ++cnt[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... |