This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int sum[26][26], mn[26][26], cont[26][26];
/// define: array[first_char][second_char]: if first_char = 1 and second_char = -1;
/// mn: largest containing the second_char
/// cont: save the sum of the previous position before the second_char appear
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < 26; i++)
for (int j = 0; j < 26; j++)
mn[i][j] = 1e9;
int ans = 0;
for (auto ch: s) {
int x = ch - 'a';
for (int y = 0; y < 26; y++) {
if (x == y) continue;
sum[x][y]++;
ans = max(ans, sum[x][y] - mn[x][y]);
sum[y][x]--;
mn[y][x] = min(mn[y][x], cont[y][x]);
cont[y][x] = sum[y][x];
ans = max(ans, sum[y][x] - mn[y][x]);
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |