#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
if (a.empty()) return o << "{}";
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
vv (int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
vv (int n, int m) : vector <vector <T>> (n, vector <T>(m)) {}
vv () {}
};
template <typename T> struct vvv : vector <vv <T>> {
vvv (int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
vvv (int n, int m, int k) : vector <vv <T>> (n, vv <T>(m, k)) {}
vvv () {}
};
#ifdef Doludu
#define test(args...) abc("[" + string(#args) + "]", args)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#endif
const int mod = 998244353, N = 300005, logN = 18, G = 3;
struct PAM {
int ch[N][26], cnt[N], fail[N], len[N], sz;
string s;
// 0 -> even root, 1 -> odd root
PAM (string _s) : s(_s) {
sz = 0;
extend(), extend();
len[0] = 0, fail[0] = 1, len[1] = -1;
int lst = 1;
for (int i = 0; i < s.length(); ++i) {
while (s[i - len[lst] - 1] != s[i])
lst = fail[lst];
if (!ch[lst][s[i] - 'a']) {
int idx = extend();
len[idx] = len[lst] + 2;
int now = fail[lst];
while (s[i - len[now] - 1] != s[i])
now = fail[now];
fail[idx] = ch[now][s[i] - 'a'];
ch[lst][s[i] - 'a'] = idx;
}
lst = ch[lst][s[i] - 'a'], cnt[lst]++;
}
}
int extend() {
fill(ch[sz], ch[sz] + 26, 0), sz++;
return sz - 1;
}
lli solve() {
for (int i = sz - 1; i > 1; --i) {
cnt[fail[i]] += cnt[i];
}
lli ans = 0;
for (int i = 2; i < sz; ++i) {
ans = max(ans, 1ll * len[i] * cnt[i]);
}
return ans;
}
};
int main () {
owo;
string s;
cin >> s;
PAM solver(s);
cout << solver.solve() << '\n';
}
Compilation message
palindrome.cpp: In constructor 'PAM::PAM(std::string)':
palindrome.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0; i < s.length(); ++i) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
34260 KB |
Output is correct |
2 |
Correct |
15 ms |
34260 KB |
Output is correct |
3 |
Correct |
16 ms |
34236 KB |
Output is correct |
4 |
Correct |
17 ms |
34252 KB |
Output is correct |
5 |
Correct |
16 ms |
34260 KB |
Output is correct |
6 |
Correct |
15 ms |
34260 KB |
Output is correct |
7 |
Correct |
15 ms |
34260 KB |
Output is correct |
8 |
Correct |
15 ms |
34260 KB |
Output is correct |
9 |
Correct |
15 ms |
34328 KB |
Output is correct |
10 |
Correct |
16 ms |
34340 KB |
Output is correct |
11 |
Correct |
15 ms |
34300 KB |
Output is correct |
12 |
Correct |
15 ms |
34316 KB |
Output is correct |
13 |
Correct |
14 ms |
34312 KB |
Output is correct |
14 |
Correct |
16 ms |
34416 KB |
Output is correct |
15 |
Correct |
15 ms |
34244 KB |
Output is correct |
16 |
Correct |
15 ms |
34260 KB |
Output is correct |
17 |
Correct |
18 ms |
34308 KB |
Output is correct |
18 |
Correct |
14 ms |
34272 KB |
Output is correct |
19 |
Correct |
17 ms |
34328 KB |
Output is correct |
20 |
Correct |
16 ms |
34336 KB |
Output is correct |
21 |
Correct |
14 ms |
34260 KB |
Output is correct |
22 |
Correct |
14 ms |
34260 KB |
Output is correct |
23 |
Correct |
15 ms |
34376 KB |
Output is correct |
24 |
Correct |
14 ms |
34260 KB |
Output is correct |
25 |
Correct |
17 ms |
34332 KB |
Output is correct |
26 |
Correct |
14 ms |
34260 KB |
Output is correct |
27 |
Correct |
16 ms |
34340 KB |
Output is correct |
28 |
Correct |
15 ms |
34260 KB |
Output is correct |
29 |
Correct |
15 ms |
34268 KB |
Output is correct |
30 |
Correct |
15 ms |
34312 KB |
Output is correct |
31 |
Correct |
13 ms |
34316 KB |
Output is correct |
32 |
Correct |
16 ms |
34260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
34260 KB |
Output is correct |
2 |
Correct |
14 ms |
34260 KB |
Output is correct |
3 |
Correct |
17 ms |
34264 KB |
Output is correct |
4 |
Correct |
18 ms |
34260 KB |
Output is correct |
5 |
Correct |
17 ms |
34360 KB |
Output is correct |
6 |
Correct |
16 ms |
34304 KB |
Output is correct |
7 |
Correct |
15 ms |
34332 KB |
Output is correct |
8 |
Correct |
16 ms |
34332 KB |
Output is correct |
9 |
Correct |
15 ms |
34260 KB |
Output is correct |
10 |
Correct |
14 ms |
34260 KB |
Output is correct |
11 |
Correct |
18 ms |
34352 KB |
Output is correct |
12 |
Correct |
15 ms |
34260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
34352 KB |
Output is correct |
2 |
Correct |
17 ms |
34388 KB |
Output is correct |
3 |
Correct |
17 ms |
34388 KB |
Output is correct |
4 |
Correct |
17 ms |
34292 KB |
Output is correct |
5 |
Correct |
18 ms |
34392 KB |
Output is correct |
6 |
Correct |
18 ms |
34360 KB |
Output is correct |
7 |
Correct |
16 ms |
34300 KB |
Output is correct |
8 |
Correct |
15 ms |
34388 KB |
Output is correct |
9 |
Correct |
15 ms |
34376 KB |
Output is correct |
10 |
Correct |
15 ms |
34388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
34608 KB |
Output is correct |
2 |
Correct |
20 ms |
34596 KB |
Output is correct |
3 |
Correct |
19 ms |
34580 KB |
Output is correct |
4 |
Correct |
22 ms |
34592 KB |
Output is correct |
5 |
Correct |
19 ms |
34588 KB |
Output is correct |
6 |
Correct |
19 ms |
34624 KB |
Output is correct |
7 |
Correct |
19 ms |
34592 KB |
Output is correct |
8 |
Correct |
16 ms |
34564 KB |
Output is correct |
9 |
Correct |
19 ms |
34644 KB |
Output is correct |
10 |
Correct |
18 ms |
34640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
35292 KB |
Output is correct |
2 |
Correct |
27 ms |
35572 KB |
Output is correct |
3 |
Correct |
27 ms |
35672 KB |
Output is correct |
4 |
Correct |
28 ms |
35664 KB |
Output is correct |
5 |
Correct |
30 ms |
35652 KB |
Output is correct |
6 |
Correct |
29 ms |
35668 KB |
Output is correct |
7 |
Correct |
29 ms |
35652 KB |
Output is correct |
8 |
Correct |
20 ms |
35652 KB |
Output is correct |
9 |
Correct |
19 ms |
35768 KB |
Output is correct |
10 |
Correct |
26 ms |
35564 KB |
Output is correct |
11 |
Correct |
27 ms |
35676 KB |
Output is correct |
12 |
Correct |
20 ms |
35676 KB |
Output is correct |