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 int long long
using namespace std;
const int MAXN = 1e5 + 10;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng);
return u;
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
double ono = 1e9;
int opt_l = 1, opt_r = 1;
for(int cnt=1; cnt<=26; cnt++) {
int j=0;
int freq[26];
for(int i=0; i<26; i++) freq[i] = 0;
int distin = 0;
for(int i=1; i<=n; i++) {
if(i>1) {
freq[s[i-2] - 'a']--;
if(freq[s[i-2] - 'a'] == 0) distin--;
}
while(j+1 <= n && distin + (freq[s[j] - 'a'] == 0) <= cnt) {
freq[s[j] - 'a']++;
if(freq[s[j] - 'a'] == 1) distin++;
j++;
}
if(distin == cnt && i <= j) {
if(cnt * 1.0 / (j-i+1) < ono) {
ono = cnt * 1.0 / (j-i+1);
opt_l = i, opt_r = j;
}
}
}
}
cout << opt_l << ' ' << opt_r << '\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... |