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 oo = (int)1e9 + 7;
int main() {
int n; cin >> n;
string s; cin >> s;
vector<vector<int>> pos(26, vector<int>());
for(int i = 0; i < n; ++i) {
pos[s[i] - 'a'].push_back(i);
}
int ans = 0;
for(int c1 = 0; c1 < 26; ++c1) {
for(int c2 = 0; c2 < 26; ++c2) {
if (c1 == c2) continue;
vector<int> p(pos[c1].size() + pos[c2].size());
merge(pos[c1].begin(), pos[c1].end(), pos[c2].begin(), pos[c2].end(), p.begin());
// printf("c1, c2: %d %d\n", c1, c2);
// for(int i: p) printf("%d ", i);
// puts("");
vector<int> a(p.size());
for(int i = 0; i < p.size(); ++i) {
a[i] = (s[p[i]] - 'a' == c1) ? 1 : -1;
}
int sumI = 0, sumJ = 0, minF = oo;
int j = 0;
for(int i = 0; i < p.size(); ++i) {
sumI += a[i];
if (a[i] == -1) {
while (j <= i) {
minF = min(minF, sumJ);
sumJ += a[j++];
}
}
ans = max(ans, sumI - minF);
}
}
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
roz.cpp: In function 'int main()':
roz.cpp:29:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i = 0; i < p.size(); ++i) {
| ~~^~~~~~~~~~
roz.cpp:36:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i = 0; i < p.size(); ++i) {
| ~~^~~~~~~~~~
# | 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... |