# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
871662 | vjudge1 | Difference (POI11_roz) | C++17 | 1099 ms | 11404 KiB |
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"
#define ii pair <int, int>
#define F first
#define S second
using namespace std;
const int N = 1e6+5;
int n;
char a[N];
int sum[N];
int pre[N];
vector <int> save[30];
int Get(int i, int j) {
return sum[j] - sum[i-1];
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
for (int i = 1 ; i <= n ; i++) {
cin >> a[i];
save[a[i]-'a'].push_back(i);
}
int res = 0;
for (int c1 = 0 ; c1 < 26 ; c1++)
for (int c2 = 0 ; c2 < 26 ; c2++) {
if (c1 == c2) continue;
vector <ii> pos;
pos.push_back(ii(0, 0));
for (int i : save[c1]) pos.push_back(ii(i, 1));
for (int i : save[c2]) pos.push_back(ii(i, -1));
sort(pos.begin(), pos.end());
int cur = 0, last = 0;
for (int i = 1 ; i < pos.size() ; i++) {
cur += pos[i].S;
if (pos[i].S == -1) last = i;
if (last) res = max(res, cur-pre[last-1]);
pre[i] = min(cur, pre[i-1]);
}
}
cout << res;
return 0;
}
Compilation message (stderr)
# | 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... |