#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define forn(i, l, r) for(int i = l; i <= r; ++i)
#define ford(i, r, l) for(int i = r; i >= l; --i)
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "palindrome"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
inline int readInt() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}
const int N = 5e5 + 4;
const int M = 3e5 + 3;
const int K = 22;
const int INF = 1e9 + 3;
const ll LINF = 1e18;
const int A = 26 + 2;
int n;
string s;
int sz[N], suf[N], nx[N][A];
int cnt[N];
void solve()
{
cin >> s;
n = sz(s);
suf[0] = 0; sz[0] = -1;
suf[1] = 0; sz[1] = 0;
int cur_suf = 1;
int num_node = 1;
for(int i = 0; i < sz(s); ++i)
{
while(s[i] != s[i - sz[cur_suf] - 1]) cur_suf = suf[cur_suf];
if(!nx[cur_suf][s[i] - 'a'])
{
int p = suf[cur_suf];
while(s[i] != s[i - sz[p] - 1]) p = suf[p];
p = max(1, nx[p][s[i] -'a']);
nx[cur_suf][s[i] - 'a'] = ++num_node;
suf[num_node] = p; sz[num_node] = sz[cur_suf] + 2;
}
++cnt[nx[cur_suf][s[i] - 'a']];
cur_suf = nx[cur_suf][s[i] - 'a'];
}
ll res = 0;
ford(i, num_node, 1)
{
cnt[suf[i]] += cnt[i];
maximize(res, 1ll * sz[i] * cnt[i]);
}
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int TC = 1;
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
while(TC--)
{
solve();
cout << endl;
}
return 0;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
palindrome.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4568 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4696 KB |
Output is correct |
30 |
Correct |
1 ms |
4440 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4564 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5724 KB |
Output is correct |
4 |
Correct |
2 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
2 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15964 KB |
Output is correct |
2 |
Correct |
9 ms |
16056 KB |
Output is correct |
3 |
Correct |
8 ms |
16020 KB |
Output is correct |
4 |
Correct |
8 ms |
15964 KB |
Output is correct |
5 |
Correct |
10 ms |
15960 KB |
Output is correct |
6 |
Correct |
6 ms |
13148 KB |
Output is correct |
7 |
Correct |
8 ms |
14300 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
7516 KB |
Output is correct |
10 |
Correct |
7 ms |
14428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
39140 KB |
Output is correct |
2 |
Correct |
22 ms |
39136 KB |
Output is correct |
3 |
Correct |
21 ms |
39396 KB |
Output is correct |
4 |
Correct |
21 ms |
39396 KB |
Output is correct |
5 |
Correct |
29 ms |
39396 KB |
Output is correct |
6 |
Correct |
20 ms |
35556 KB |
Output is correct |
7 |
Correct |
19 ms |
33508 KB |
Output is correct |
8 |
Correct |
4 ms |
5344 KB |
Output is correct |
9 |
Correct |
5 ms |
5348 KB |
Output is correct |
10 |
Correct |
22 ms |
32996 KB |
Output is correct |
11 |
Correct |
22 ms |
39556 KB |
Output is correct |
12 |
Correct |
6 ms |
8420 KB |
Output is correct |