This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of God
// Hope is last to die
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC optimize("avx2")
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
// #define int long long
#define S second
#define F first
#define mp make_pair
#define smax(xyxy, yxy) (xyxy) = max((xyxy), (yxy))
#define smin(xyxy, yxy) (xyxy) = min((xyxy), (yxy))
#define all(xyxy) (xyxy).begin(), (xyxy).end()
#define len(xyxy) ((int)(xyxy).size())
const int maxn = 1e5 + 5;
const int inf = 1e9 + 7;
int n, last[50];
string s;
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> s;
for(int i = 0; i < 26; i++) last[i] = -1;
ll l = 0, r = 1;
ld ans = 1;
for(int i = n - 1; i >= 0; i--){
last[s[i] - 'a'] = i;
vector<int> vec;
for(int c = 0; c < 26; c++) if(last[c] != -1) vec.pb(last[c]);
sort(all(vec));
vec.pb(n);
for(int j = 1; j < vec.size(); j++){
ld res = 1.0 * j / (vec[j] - i);
if(res < ans){
ans = res;
l = i;
r = vec[j];
}
}
}
cout << l + 1 << ' ' << r << '\n';
return 0;
}
Compilation message (stderr)
nivelle.cpp: In function 'int32_t main()':
nivelle.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int j = 1; j < vec.size(); j++){
| ~~^~~~~~~~~~~~
# | 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... |