#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mci map<char,int>
const int N = 6e5 + 1;
int cur = 0;
int tot = 0;
vector<mci> nxt;
vector<int> len;
vector<int> link;
void NewNode() {
nxt.pb({});
len.pb(0);
link.pb(0);
}
int cnt[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
string s; cin >> s;
NewNode(); ++tot;
NewNode(); ++tot;
len[0] = -1;
for(int i = 0 ; i < s.size() ; ++i) {
while (1) {
if(i > len[cur] && s[i - len[cur] - 1] == s[i])
break;
cur = link[cur];
}
if (nxt[cur].count(s[i])) {
cur = nxt[cur][s[i]];
cnt[cur]++;
continue;
}
NewNode();
nxt[cur][s[i]] = tot;
len[tot] = len[cur] + 2;
cnt[tot] = 1;
if (len[tot] == 1) {
link[tot] = 1;
cur = tot++;
continue;
}
while (1) {
cur = link[cur];
if (i > len[cur] && s[i - len[cur] - 1] == s[i]) {
link[tot] = nxt[cur][s[i]];
break;
}
}
cur = tot++;
}
vector<int> vec(tot - 1);
iota(vec.begin(),vec.end(),1);
sort(vec.begin(),vec.end(),[&](int x,int y) {
return len[x] > len[y];
});
long long ans = 0;
for(int x : vec)
cnt[link[x]] += cnt[x],
ans = max(ans,1ll * cnt[x] * len[x]);
cout << ans << endl;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:36:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < s.size() ; ++i) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
392 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
436 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
420 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1588 KB |
Output is correct |
2 |
Correct |
5 ms |
1716 KB |
Output is correct |
3 |
Correct |
5 ms |
1716 KB |
Output is correct |
4 |
Correct |
5 ms |
1716 KB |
Output is correct |
5 |
Correct |
5 ms |
1588 KB |
Output is correct |
6 |
Correct |
5 ms |
1588 KB |
Output is correct |
7 |
Correct |
5 ms |
1588 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
1076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
11676 KB |
Output is correct |
2 |
Correct |
34 ms |
11684 KB |
Output is correct |
3 |
Correct |
28 ms |
11544 KB |
Output is correct |
4 |
Correct |
34 ms |
11588 KB |
Output is correct |
5 |
Correct |
32 ms |
11548 KB |
Output is correct |
6 |
Correct |
25 ms |
10528 KB |
Output is correct |
7 |
Correct |
28 ms |
10528 KB |
Output is correct |
8 |
Correct |
8 ms |
632 KB |
Output is correct |
9 |
Correct |
13 ms |
3120 KB |
Output is correct |
10 |
Correct |
27 ms |
10528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
41052 KB |
Output is correct |
2 |
Correct |
103 ms |
41040 KB |
Output is correct |
3 |
Correct |
106 ms |
41016 KB |
Output is correct |
4 |
Correct |
109 ms |
41048 KB |
Output is correct |
5 |
Correct |
104 ms |
40952 KB |
Output is correct |
6 |
Correct |
96 ms |
41052 KB |
Output is correct |
7 |
Correct |
75 ms |
28504 KB |
Output is correct |
8 |
Correct |
20 ms |
1284 KB |
Output is correct |
9 |
Correct |
20 ms |
1280 KB |
Output is correct |
10 |
Correct |
77 ms |
27868 KB |
Output is correct |
11 |
Correct |
93 ms |
41052 KB |
Output is correct |
12 |
Correct |
25 ms |
4088 KB |
Output is correct |