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>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
typedef long double ld;
int main()
{
//freopen("army.in","r",stdin); freopen("army.out","w",stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
bool f = 1;
for (int i = 0; i < n; i++)
if (s[i] != 'a' && s[i] != 'b') f = 0;
ld ans = 1e18, l, r;
if (f)
{
char lst = s[0];
int k = 1;
for (int i = 1; i < n; i++)
{
if (lst == s[i]) {k++; continue;}
ld x = 1, y = k;
if (x / y < ans) {ans = x / y; r = i - 1; l = i - k;}
lst = s[i];
k = 1;
}
ld x = 1, y = k;
if (x / y < ans) {ans = x / y; r = n - 1; l = n - k;}
x = 2; y = n;
if (x / y < ans) {ans = x / y; r = n - 1; l = 0;}
cout << l << " " << r << endl;
exit(0);
}
for (int i = 0; i < n; i++)
{
set <char> se; se.clear();
for (int j = i; j < n; j++)
{
se.insert(s[j]);
ld x = sz(se), y = j - i + 1;
if (ans > x / y) {ans = x / y; l = i; r = j;}
}
}
cout << l + 1 << " " << r + 1 << endl;
}
Compilation message (stderr)
nivelle.cpp: In function 'int main()':
nivelle.cpp:81:33: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
cout << l + 1 << " " << r + 1 << endl;
^
nivelle.cpp:81:17: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
cout << l + 1 << " " << r + 1 << endl;
^
# | 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... |