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 <algorithm>
#include <set>
#include <deque>
#include <queue>
using namespace std;
int *arr, **occ;
int main(){
int n;
cin >> n;
char c;
arr = new int[n];
occ = new int*[n+1];
for(int i = 0; i < n; i++){
cin >> c;
arr[i] = c - 'a';
occ[i] = new int[26];
}
occ[n] = new int[26];
occ++;
for(int i = 0; i < 26; i++) occ[-1][i] = occ[0][i] = 0;
occ[0][arr[0]] = 1;
for(int i = 1; i < n; i++){
for(int j = 0; j < 26; j++){
occ[i][j] = occ[i-1][j];
}
occ[i][arr[i]]++;
}
int ml = 0, mr = 0;
double m = 1;
for(int i = 0; i < n; i++){
set<int> x;
for(int j = i; j < n; j++){
x.insert(arr[j]);
if((double)x.size() / (j - i + 1) < m){
ml = i;
mr = j;
m = (double)x.size() / (j - i + 1);
}
}
}
cout << (ml+1) << ' ' << (mr+1) << '\n';
}
# | 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... |