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;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int AL = 26;
int las[AL];
struct F{
int A;
int B;
int li;
int ri;
bool operator< ( const F &C) const {
return A * C.B < C.A * B;
}
};
int main(){
fastIO;
int n;
cin >> n;
for(int i = 0 ; i < AL; i ++ ){
las[i]=-1;
}
F cur = {1, 1, 1, 1};
char in;
int d;
set<int> pos;
pos.insert(0);
int cnt;
for(int i = 1; i <= n; i ++){
cin >> in;
d = in - 'a';
if(las[d] != -1){
pos.erase(las[d]);
}
pos.insert(i);
auto it = pos.end();
it--;
cnt = 0;
F tri;
while(it != pos.begin()){
auto pv = it;
pv -- ;
cnt ++ ;
tri = {cnt, i - (*pv), (*pv) + 1, i};
cur = min(cur, tri);
it = pv;
}
las[d]=i;
}
cout << cur.li << " " << cur.ri << "\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... |