#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define pb push_back
#define N +300500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e9)
#define el '\n'
#define Max_A int(1e9)
//#define el endl
#define pii pair <int, int>
#define piii pair <int, pair <int, int> >
#define psi pair <string, int>
#define err ld(1e-9)
#define Max_S int(3e6)
#define last(x) x.back()
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector<int>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
ll ans, cur;
string s;
int i, n;
char c;
int main()
{
// srand(time(0));
cout.precision(3);
cout << fixed;
ios_base::sync_with_stdio(0);
iostream::sync_with_stdio(0);
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
// in("input.txt");
// out("output.txt");
cin >> s;
n = sz(s);
for (i = 0; i < n; i++)
{
char old_c = s[i];
for (c = 'a'; c <= 'z'; c++)
{
cur = 0;
s[i] = c;
vi d1(n);
int l = 0, r = -1;
for (int j = 0; j < n; j++)
{
int k = ((j > r) ? 1 : min(d1[l + r - j],
r - j + 1));
while (j+k < n && j-k >= 0 && s[j+k] == s[j-k]) k++;
d1[j] = k;
if (j + k - 1 > r)
{
l = j - k + 1;
r = j + k - 1;
}
}
vi d2(n);
l = 0;
r = -1;
for (int j = 0; j < n; j++)
{
int k = ((j > r) ? 0 : min (d2[l + r - j + 1],
r - j + 1));
while (j+k < n && j-k-1 >= 0 && s[j+k] == s[j-k-1]) ++k;
d2[j] = k;
if (j + k - 1 > r)
{
l = j - k;
r = j + k - 1;
}
}
for (int j = 0; j < n; j++)
cur += d1[j] + d2[j];
ans = max(ans, cur);
s[i] = old_c;
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1085 ms |
1816 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |