# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40289 | IvanC | Difference (POI11_roz) | C++14 | 255 ms | 17260 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 MAXN = 1e6+10;
const int ALPHABET_SIZE = 26;
vector<int> aparece[ALPHABET_SIZE];
int vetor[MAXN],soma[MAXN],N,resposta;
int calc(int a,int b){return soma[b] - soma[a-1];}
int main(){
scanf("%d",&N);
for(int i = 1;i<=N;i++){
char c;
scanf(" %c",&c);
vetor[i] = c - 'a';
aparece[vetor[i]].push_back(i);
}
for(int letra = 0;letra<ALPHABET_SIZE;letra++){
for(int i = 1;i<=N;i++){
soma[i] = soma[i-1] + (vetor[i] == letra);
}
soma[N+1] = soma[N];
for(int outra = 0;outra < ALPHABET_SIZE;outra++){
if(outra == letra) continue;
int minimo = 0;
for(int i = 0;i<aparece[outra].size();i++){
int proxima = 0;
if(i + 1 == aparece[outra].size()) proxima = N;
else proxima = aparece[outra][i+1] - 1;
int j = i + 1;
resposta = max(resposta, calc(1,proxima) - j - minimo );
minimo = min(minimo, -j + calc(1,aparece[outra][i]) );
}
}
}
printf("%d\n",resposta);
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... |