#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()
{
// freopen("DIFF.INP", "r", stdin);
// freopen("DIFF.OUT", "w", stdout);
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++) pf[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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
232 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
640 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
2416 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
54 ms |
2152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
2416 KB |
Output is correct |
2 |
Correct |
57 ms |
2152 KB |
Output is correct |
3 |
Correct |
54 ms |
2152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
2416 KB |
Output is correct |
2 |
Correct |
64 ms |
2416 KB |
Output is correct |
3 |
Correct |
68 ms |
2288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
2416 KB |
Output is correct |
2 |
Correct |
72 ms |
2416 KB |
Output is correct |
3 |
Correct |
59 ms |
2416 KB |
Output is correct |