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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool win(int l, int r, vector<int>&lista){
int p=r-l+1;
vector<int>copia(p);
for (int i=0; i<p; i++) copia[i]=lista[l+i];
sort(copia.begin(), copia.end());
int count=1, maxi=0, ant=copia[0];
for (int i=1; i<p; i++){
if (copia[i]!=ant){
maxi=max(maxi, count);
count=1;
ant=copia[i];
}else count++;
}if (maxi<count) maxi=count;
if (maxi*2>p) return true;
else return false;
}
int main(){
int n;
cin>>n;
vector<int>lista(n);
int ans=n;
for (int i=0; i<n; i++) cin>>lista[i];
for (int i=0; i<n; i++){
for (int j=i+1; j<n; j++){
if (win(i, j, lista)) ans++;
}
}cout<<ans<<endl;
return 0;
}
# | 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... |