#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;
ll f(string s)
{
cur = 0;
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];
return cur;
}
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);
ans = f(s);
for (i = 0; i < n; i++)
{
char old_c = s[i];
if (i < n - 1)
{
s[i] = s[i + 1];
ans = max(ans, f(s));
}
if (i > 0)
{
s[i] = s[i - 1];
ans = max(ans, f(s));
}
s[i] = old_c;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
557 ms |
536 KB |
Output is correct |
2 |
Correct |
546 ms |
384 KB |
Output is correct |
3 |
Correct |
402 ms |
508 KB |
Output is correct |
4 |
Correct |
180 ms |
384 KB |
Output is correct |
5 |
Correct |
457 ms |
504 KB |
Output is correct |
6 |
Correct |
560 ms |
440 KB |
Output is correct |
7 |
Incorrect |
379 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
1744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |