Submission #40289

#TimeUsernameProblemLanguageResultExecution timeMemory
40289IvanCDifference (POI11_roz)C++14
100 / 100
255 ms17260 KiB
#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)

roz.cpp: In function 'int main()':
roz.cpp:24:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0;i<aparece[outra].size();i++){
                   ^
roz.cpp:26:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(i + 1 == aparece[outra].size()) proxima = N;
              ^
roz.cpp:9:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
                ^
roz.cpp:12:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c",&c);
                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...