#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
const int maxn = 1e6 + 5, abc = 26;
int ans = 0;
int pf[abc][abc], pfmin[abc][abc], last[abc][abc];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < abc; i++) for (int j = 0; j < abc; j++) pfmin[i][j] = 1e9;
for (int i = 0; i < n; i++)
{
int a = s[i] - 'a';
for (int b = 0; b < abc; b++) if (a ^ b)
{
pf[a][b]++;
ans = max(ans, pf[a][b] - pfmin[a][b]);
pfmin[b][a] = min(pfmin[b][a], last[b][a]);
last[b][a] = --pf[b][a];
ans = max(ans, pf[b][a] - pfmin[b][a]);
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
588 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
2408 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
73 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
2280 KB |
Output is correct |
2 |
Correct |
72 ms |
2144 KB |
Output is correct |
3 |
Correct |
73 ms |
2144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
2408 KB |
Output is correct |
2 |
Correct |
86 ms |
2408 KB |
Output is correct |
3 |
Correct |
83 ms |
2280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
2408 KB |
Output is correct |
2 |
Correct |
86 ms |
2408 KB |
Output is correct |
3 |
Correct |
80 ms |
2408 KB |
Output is correct |