This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// cre: nnhzzz
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <unordered_set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <cmath>
#include <cassert>
using namespace std;
//-------------------------------------------------------------//
#define __nnhzzz__ signed main()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define repdis(i,be,en,j) for(int i = (be); i<=(en); i+=j)
#define repd(i,be,en) for(int i = (be); i>=(en); i--)
#define rep(i,be,en) for(int i = (be); i<=(en); i++)
#define reset(x,val) memset((x),(val),sizeof(x))
#define bit(i,j) ((i>>j)&1ll)
#define mask(i) (1ll<<i)
#define FULL(i) (mask(i)-1)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int,int>>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define endl "\n"
#define ull unsigned long long
#define ll long long
#define ld long double
#define int long long
#define fi first
#define se second
#define C make_pair
#define vec vector
//-------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}
//-------------------------------------------------------------//
const int maxn = 5e5+7;
const int MOD = 1e9+7;
const int oo = 1e18+7;
const int INF = 0x3f3f3f3f;
const int LLINF = 0x3f3f3f3f3f3f3f3f;
// const int base = 311;
// const ld PI = 3.1415926535897932384626433832795;
// const ld EPS = 1e-9;
//-------------------------------------------------------------//
// int dx[] = {-1, 1, 0, 0};
// int dy[] = {0, 0, -1, 1};
void solve(){
int n;
string s;
cin >> n >> s;
int res = 26,l = -1,r = -1;
vi last(26,-1),sorted(27,-1);
for(int i = 0; i<n; i++) {
int c = s[i] - 'a';
sorted.erase(find(sorted.begin(),sorted.end(),last[c]));
last[c] = i;
sorted.insert(sorted.begin(), i);
for(int j = 1; j<=26; j++){
if(j*(r-l+1)<=res*(i-sorted[j])){
res = j;
l = sorted[j]+1;
r = i;
}
}
}
cout << l+1 << " " << r+1;
}
//-------------------------------------------------------------//
__nnhzzz__{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "test"
if(fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
int test = 1;
while(test--){
solve();
}
cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
return 0;
}
Compilation message (stderr)
nivelle.cpp: In function 'int main()':
nivelle.cpp:118:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
118 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:119:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
119 | freopen(name".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... |