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;
int n, lst[27][100002];
string s;
int L, R, col;
void chk(int st, int dr, int cnt)
{
if(L == 0)
{
L = st;
R = dr;
col = cnt;
}
else
{
long long a = cnt;
long long b = dr - st + 1;
long long c = col;
long long d = R - L + 1;
if(a * d < b * c)
{
L = st;
R = dr;
col = cnt;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
cin >> s;
s = ' ' + s;
for(int i = 1; i <= n; ++i)
{
for(int j = 0; j <= 25; ++j)
lst[j][i] = lst[j][i-1];
lst[s[i] - 'a'][i] = i;
vector<int> v;
for(int j = 0; j <= 25; ++j)
if(lst[j][i] != 0)
v.push_back(lst[j][i]);
v.push_back(0);
sort(v.begin(), v.end());
for(int x = v.size() - 1; x > 0; --x)
chk(v[x - 1] + 1, i, v.size() - x);
}
cout << L << " " << R << '\n';
return 0;
}
# | 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... |