#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 + 1][A], ll[N + 1], mm[N + 1];
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) {
if (ij % 2 == 0) {
h = ij / 2;
mm[i]++, mm[h]--, ll[h]++, ll[h + 1]--, mm[h + 1]++, mm[j + 1]--;
} else
mm[i]++, mm[j + 1]--;
ll[0]++, ll[i]--, ll[j + 1]++, ll[n]--;
} else
kk[i_][cc[j_] - 'a']++, kk[j_][cc[i_] - 'a']++;
}
for (i = 1; i < n; i++)
ll[i] += ll[i - 1];
for (i = 1; i < n; i++)
mm[i] += mm[i - 1];
k_ = 0;
for (i = 0; i < n; i++)
for (a = 0; a < A; a++)
k_ = max(k_, kk[i][a] + ll[i] + (cc[i] == a + 'a' ? mm[i] : 0));
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 |
0 ms |
332 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 |
Correct |
68 ms |
1260 KB |
Output is correct |
2 |
Correct |
63 ms |
1396 KB |
Output is correct |
3 |
Correct |
3 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
844 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
2 ms |
1356 KB |
Output is correct |
7 |
Correct |
1 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
22224 KB |
Output is correct |
2 |
Execution timed out |
1078 ms |
6788 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |