#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)1e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}
int n, suff[MAXN], c[MAXN], nc[MAXN], tmp[MAXN], cnt[MAXN], timer;
char s[MAXN];
int lcp[MAXN], pos[MAXN];
inline void calc() {
rep(i, 1, max(n, 256)) cnt[i] += cnt[i - 1];
per(i, max(n, 256), 0) cnt[i + 1] = cnt[i];
cnt[0] = 0;
}
inline void SA() {
memset(cnt, 0, sizeof cnt);
s[n++] = (char)0;
rep(i, 0, n - 1) cnt[s[i]]++;
calc();
rep(i, 0, n - 1) {
suff[cnt[s[i]]++] = i;
}
c[suff[0]] = 0;
rep(i, 1, n - 1) {
if(s[suff[i]] == s[suff[i - 1]]) c[suff[i]] = c[suff[i - 1]];
else c[suff[i]] = c[suff[i - 1]] + 1;
}
for(int len = 1; len <= n; len += len) {
rep(i, 0, n - 1) tmp[i] = (suff[i] - len + n) % n;
memset(cnt, 0, sizeof cnt);
rep(i, 0, n - 1) cnt[c[suff[i]]]++;
calc();
rep(i, 0, n - 1) suff[cnt[c[tmp[i]]]++] = tmp[i];
nc[suff[0]] = 0;
rep(i, 1, n - 1) {
pair < int, int > cur = { c[suff[i]], c[(suff[i] + len) % n] };
pair < int, int > last = { c[suff[i - 1]], c[(suff[i - 1] + len) % n] };
if(cur == last) nc[suff[i]] = nc[suff[i - 1]];
else nc[suff[i]] = nc[suff[i - 1]] + 1;
}
rep(i, 0, n - 1) c[i] = nc[i];
}
n--;
rep(i, 0, n - 1) suff[i] = suff[i + 1];
}
void build() {
rep(i, 0, n - 1) pos[suff[i]] = i;
int k = 0;
rep(i, 0, n - 1) {
if(k > 0) k--;
if(pos[i] == n - 1) {
k = 0;
lcp[n - 1] = 0;
}
else {
int j = suff[pos[i] + 1];
while(k <= n && max(i + k, j + k) < n && s[(i + k) % n] == s[(j + k) % n]) k++;
lcp[pos[i]] = k;
}
}
}
bool ok(int l, int r) {
if(l > r) return 1;
if(s[l] != s[r]) return 0;
return ok(l+1, r-1);
}
int main() {
#ifdef accepted
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
// onlycin;
scanf("%s", s);
n = strlen(s);
SA();
build();
ll res = 0ll;
rep(i, 0, n-1) {
rep(len, 1, n-suff[i]) {
if(!ok(suff[i], suff[i]+len-1)) continue;
int l = i, cnt = 1;
while(l < n && lcp[l] >= len) l++, cnt++;
updmax(res, len*1ll*cnt);
}
// cerr << lcp[i] << ' ';
}
cout << res << nxtl;
return 0;
}
Compilation message
palindrome.cpp: In function 'void SA()':
palindrome.cpp:45:27: warning: array subscript has type 'char' [-Wchar-subscripts]
rep(i, 0, n - 1) cnt[s[i]]++;
^
palindrome.cpp:48:16: warning: array subscript has type 'char' [-Wchar-subscripts]
suff[cnt[s[i]]++] = i;
^
palindrome.cpp: In function 'int main()':
palindrome.cpp:102:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", s);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
808 KB |
Output is correct |
4 |
Correct |
2 ms |
884 KB |
Output is correct |
5 |
Correct |
2 ms |
884 KB |
Output is correct |
6 |
Correct |
2 ms |
884 KB |
Output is correct |
7 |
Correct |
2 ms |
952 KB |
Output is correct |
8 |
Correct |
2 ms |
952 KB |
Output is correct |
9 |
Correct |
2 ms |
968 KB |
Output is correct |
10 |
Correct |
2 ms |
968 KB |
Output is correct |
11 |
Correct |
2 ms |
968 KB |
Output is correct |
12 |
Correct |
2 ms |
968 KB |
Output is correct |
13 |
Correct |
2 ms |
968 KB |
Output is correct |
14 |
Correct |
2 ms |
1004 KB |
Output is correct |
15 |
Correct |
2 ms |
1004 KB |
Output is correct |
16 |
Correct |
2 ms |
1004 KB |
Output is correct |
17 |
Correct |
2 ms |
1004 KB |
Output is correct |
18 |
Correct |
2 ms |
1004 KB |
Output is correct |
19 |
Correct |
2 ms |
1004 KB |
Output is correct |
20 |
Correct |
2 ms |
1004 KB |
Output is correct |
21 |
Correct |
2 ms |
1004 KB |
Output is correct |
22 |
Correct |
2 ms |
1004 KB |
Output is correct |
23 |
Correct |
3 ms |
1004 KB |
Output is correct |
24 |
Correct |
2 ms |
1004 KB |
Output is correct |
25 |
Correct |
2 ms |
1004 KB |
Output is correct |
26 |
Correct |
2 ms |
1004 KB |
Output is correct |
27 |
Correct |
2 ms |
1004 KB |
Output is correct |
28 |
Correct |
2 ms |
1004 KB |
Output is correct |
29 |
Correct |
2 ms |
1004 KB |
Output is correct |
30 |
Correct |
2 ms |
1004 KB |
Output is correct |
31 |
Correct |
2 ms |
1004 KB |
Output is correct |
32 |
Correct |
2 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
1048 KB |
Output is correct |
2 |
Correct |
28 ms |
1048 KB |
Output is correct |
3 |
Correct |
226 ms |
1132 KB |
Output is correct |
4 |
Correct |
5 ms |
1132 KB |
Output is correct |
5 |
Correct |
223 ms |
1132 KB |
Output is correct |
6 |
Correct |
223 ms |
1132 KB |
Output is correct |
7 |
Correct |
5 ms |
1132 KB |
Output is correct |
8 |
Correct |
81 ms |
1132 KB |
Output is correct |
9 |
Correct |
4 ms |
1132 KB |
Output is correct |
10 |
Correct |
3 ms |
1132 KB |
Output is correct |
11 |
Correct |
4 ms |
1132 KB |
Output is correct |
12 |
Correct |
6 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1066 ms |
1260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
3436 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
3436 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |