이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 42, INF = 1e18 + 42;
string str;
int n, a = INF, b = 1, l = -1, r = -1, val[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> str;
for(int i = 0; i < n; i++)
val[i] = str[i] - 'a';
for(int i = 1; i <= 26; i++) {
int fin = 0, occ[26] = {0}, t = 0;
for(int deb = 0; deb < n; deb++) {
while(fin < n && ((occ[val[fin]] && t == i) || t < i)) {
if(!occ[val[fin]])
t++;
occ[val[fin]]++;
fin++;
}
if(a * (fin - deb) > b * i) {
l = deb, r = fin;
a = i, b = (fin - deb);
}
occ[val[deb]]--;
if(!occ[val[deb]])
t--;
}
}
cout << l+1 << ' ' << r;
}
# | 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... |