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>
#define all(x) x.begin(),x.end()
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 100100;
const int M = 1000100;
const int oo = 1e9;
string s;
int n, pf[N][26], ansf, anss, se, fi;
int calc(int l, int r){
int res = 0;
for (int i = 0; i < 26; i++)
res += bool(pf[r][i] - pf[l - 1][i]);
return res;
}
bool smaller(ll x, ll y, ll a, ll b){
return x * b < a * y;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> n >> s;
for (int i = 1; i <= n; i++){
for (int j = 0; j < 26; j++)
pf[i][j] = pf[i - 1][j];
pf[i][s[i - 1] - 'a']++;
}
ansf = oo; anss = 1;
fi = se = -1;
for (int kol = 1; kol < 27; kol++){
int j = 1;
for (int i = 1; i <= n; i++){
while (j <= i && calc(j, i) > kol)
j++;
if (calc(j, i) == kol && smaller(kol, i - j + 1, ansf, anss)){
ansf = kol;
anss = i - j + 1;
fi = j;
se = i;
}
}
}
cout << fi << " " << se;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |