# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
885105 | harao | Difference (POI11_roz) | C++17 | 136 ms | 12456 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>
using namespace std;
const int N = 1e6 + 7;
int n, pre[N], ans;
string s;
vector<int> g[26];
void solve (int m) {
for(int i = 1;i <= n; i++) {
pre[i] = pre[i - 1] + ((s[i] - 'a') == m);
}
for(int k = 0;k < 26; k++) {
if(k == m) continue;
int mn = 0;
for(int i = 1;i < g[k].size(); i++) {
ans = max(ans, pre[g[k][i]] - i - mn);
mn = min(mn, pre[g[k][i-1]] - i);
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen(".inp", "r", stdin);
// freopen(".out", "w", stdout);
cin >> n;
cin >> s;
s = " " + s;
for(int i = 1;i <= n; i++)
{
g[s[i] - 'a'].push_back(i);
}
for(int i = 0;i < 26; i++) g[i].push_back(n);
for(int i = 0;i < 26; i++) solve(i);
cout << ans;
}
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... |