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>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
int n, l[30], r[30], d[30];
string s;
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> s;
s = ' ' + s;
for (int cnt=1; cnt<=26; cnt++)
{
int cur = 0;
int j=0;
r[cnt]=-1;
f1 (i, n)
{
d[s[i]-'a'] ++;
if (d[s[i]-'a'] == 1) cur++;
while (cur > cnt)
{
d[s[++j]-'a']--;
if(d[s[j]-'a'] == 0) cur--;
}
if (i-j > r[cnt]-l[cnt]+1) l[cnt] = j+1, r[cnt] = i;
}
f0 (i, 26) d[i] = 0;
}
vector <pair<int, pii> > ans;
f1 (i, 26) ans.push_back({i, {l[i], r[i]}});
sort(ans.begin(), ans.end(), [](pair<int, pii> a, pair<int, pii> b){
return a.fi * (b.se.se-b.se.fi+1)< b.fi * (a.se.se-a.se.fi+1);
});
cout << ans[0].se.fi << ' ' << ans[0].se.se;
}
Compilation message (stderr)
nivelle.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
12 | 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... |