#include <stdio.h>
#include <string.h>
#define N 100000
#define A 26
long long max(long long a, long long b) { return a > b ? a : b; }
int main() {
static long long kk[N][A], ll[N];
static char cc[N + 1];
int n, h, i, j, i_, j_, ij, a;
long long k_;
scanf("%s", cc), n = strlen(cc);
for (ij = 0; ij <= n - 1 + n - 1; ij++)
for (i = ij / 2, j = ij - i, i_ = j_ = -1; i >= 0 && j < n; i--, j++) {
if (cc[i] != cc[j]) {
if (i_ == -1)
i_ = i, j_ = j;
else
break;
}
if (i_ == -1) {
for (h = i; h <= j; h++)
if (ij % 2 != 0 || h * 2 != ij)
kk[h][cc[h] - 'a']++;
else
ll[h]++;
for (h = 0; h < i; h++)
ll[h]++;
for (h = j + 1; h < n; h++)
ll[h]++;
} else
kk[i_][cc[j_] - 'a']++, kk[j_][cc[i_] - 'a']++;
}
k_ = 0;
for (i = 0; i < n; i++)
for (a = 0; a < A; a++)
k_ = max(k_, kk[i][a] + ll[i]);
printf("%lld\n", k_);
return 0;
}
Compilation message
palinilap.c: In function 'main':
palinilap.c:15:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%s", cc), n = strlen(cc);
| ^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
2616 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |