This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
#define task "test"
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i, l, r) for( ll i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( ll i = (r) ; i >= (l) ; i-- )
#define sz(x) (int)x.size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define numBit(x) __builtin_popcount(x)
#define lb lower_bound
#define ub upper_bound
#define ar array
#define endl '\n'
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
const int N = 2e5 + 7;
const ll inf = 0x3f3f3f3f;
int n, cnt[26], p[N][26];
string s;
int calc(int l, int r) {
int cnt = 0;
forw(i, 0, 26) cnt += (p[r][i] - p[l - 1][i] > 0);
return cnt;
}
int main() {
#ifndef ONLINE_JUDGE
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
#endif
fastIO;
cin >> n >> s;
s = ' ' + s;
forw(i, 1, sz(s)) forw(j, 0, 26)
p[i][j] += p[i - 1][j] + (s[i] - 'a' == j);
ld ans = 26;
int L = -1, R = -1;
forw(k, 1, 27) forw(i, 1, n + 1) {
int l = i, r = n, res = -1;
while (l <= r) {
int mid = l + r >> 1;
if (calc(i, mid) <= k) res = mid, l = mid + 1;
else r = mid - 1;
}
if (ans != -1 && calc(i, res) == k && k * 1.0 / (res - i + 1) < ans){
ans = k * 1.0 / (res - i + 1);
L = i, R = res;
}
}
cout << L << ' ' << R << endl;
}
Compilation message (stderr)
nivelle.cpp: In function 'int main()':
nivelle.cpp:63:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
63 | int mid = l + r >> 1;
| ~~^~~
nivelle.cpp:48:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:49:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |