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;
const int N = 1e6 + 5;
int cnt[N][30];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
char x;
cin >> x;
for (char j = 'a'; j <= 'z'; j++) cnt[i][j - 'a'] = cnt[i - 1][j - 'a'];
cnt[i][x - 'a']++;
}
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
int Min = 1e9 + 7,Max = 0;
for (int k = 0; k < 26; k++) {
Max = max(Max,cnt[j][k] - cnt[i - 1][k]);
if (cnt[j][k] - cnt[i - 1][k] > 0) Min = min(Min,cnt[j][k] - cnt[i - 1][k]);
}
ans = max(ans,Max - Min);
}
cout << ans << "\n";
}
# | 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... |