/// adil sultanov | vonat1us
#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
void fin() {
#ifdef AM
freopen(".in", "r", stdin);
#endif
}
const bool flag = 0;
const int N = 1e5+10;
const int p = 31;
ll h[N], hr[N], po[N];
int mult(int a, int b) {
return a*1ll*b % MOD;
}
void ma1n() {
string s;
cin >> s;
int n = sz(s);
po[0] = 1;
for (int i = 1; i <= n; ++i) {
po[i] = mult(po[i-1], p);
}
for (int i = 0; i < n; ++i) {
h[i+1] = (h[i]*p + s[i]) % MOD;
}
reverse(all(s));
for (int i = 0; i < n; ++i) {
hr[i+1] = (hr[i]*p + s[i]) % MOD;
}
auto get = [&](int l, int r, int t) {
if (t) {
r = n-r+1;
l = n-l+1;
swap(l, r);
return (hr[r] - mult(hr[l-1], po[r-l+1]) + MOD) %MOD;
} else {
return (h[r] - mult(h[l-1], po[r-l+1]) + MOD) %MOD;
}
};
map<int, int> cnt;
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
cnt[get(i, j, 0)]++;
}
}
ll ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
if (get(i, j, 0) == get(i, j, 1)) {
ans = max(ans, cnt[get(i, j, 0)] * 1ll * (j-i+1));
}
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr), fin();
int ts = 1;
if (flag) {
cin >> ts;
}
while (ts--) {
ma1n();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
452 KB |
Output is correct |
27 |
Correct |
2 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
436 KB |
Output is correct |
2 |
Correct |
284 ms |
12980 KB |
Output is correct |
3 |
Correct |
43 ms |
332 KB |
Output is correct |
4 |
Correct |
377 ms |
21204 KB |
Output is correct |
5 |
Correct |
50 ms |
324 KB |
Output is correct |
6 |
Correct |
44 ms |
332 KB |
Output is correct |
7 |
Correct |
305 ms |
16096 KB |
Output is correct |
8 |
Correct |
50 ms |
444 KB |
Output is correct |
9 |
Correct |
426 ms |
21924 KB |
Output is correct |
10 |
Correct |
408 ms |
23640 KB |
Output is correct |
11 |
Correct |
416 ms |
23576 KB |
Output is correct |
12 |
Correct |
337 ms |
18248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
1484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
12168 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
6300 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |