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>
using namespace std;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int MAXN = 1e5 + 4;
int n;
double ans = 2e9;
pair<int, int> pos;
char a[MAXN];
main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifdef ngchuong
freopen("C.inp", "r", stdin);
freopen("C.out", "w", stdout);
#endif
cin >> n >> (a + 1);
for (int k = 1; k <= 26; k++) {
int sum = 0; vector<int> cnt(26, 0);
for (int l = 1, r = 1; r <= n; r++) {
cnt[a[r] - 'a']++;
if (cnt[a[r] - 'a'] == 1) sum++;
while (sum > k) {
if (cnt[a[l] - 'a'] == 1) sum--;
cnt[a[l] - 'a']--; l++;
}
if (sum == k && ans > double(k) / (r - l + 1)) {
ans = double(k) / (r - l + 1); pos = {l, r};
}
}
}
cout << pos.fi << ' ' << pos.se;
}
Compilation message (stderr)
nivelle.cpp:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
15 | main() {
| ^~~~
# | 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... |