# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30082 | khsoo01 | Difference (POI11_roz) | C++11 | 206 ms | 14332 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 = 1000005;
int n, sum[N], ans;
char ipt[N];
vector<int> s[26];
void solve (int I) {
for(int i=1;i<=n;i++) {
sum[i] = sum[i-1] + (ipt[i] == I);
}
for(int k=0;k<26;k++) {
if(k == I) continue;
int mn = 0;
for(int i=1;i<s[k].size();i++) {
ans = max(ans, sum[s[k][i]] - i - mn);
mn = min(mn, sum[s[k][i-1]] - i);
}
}
}
int main()
{
scanf("%d%s",&n,ipt+1);
for(int i=1;i<=n;i++) {
ipt[i] -= 'a';
s[ipt[i]].push_back(i);
}
for(int i=0;i<26;i++) s[i].push_back(n);
for(int i=0;i<26;i++) solve(i);
printf("%d\n",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... |