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<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair
#ifndef ONLINE_JUDGE
# define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
# define LOG(x) ((void)0)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;
template<typename T> T getint() {
T val=0;
char c;
bool neg=false;
while((c=gc()) && !(c>='0' && c<='9')) {
neg|=c=='-';
}
do {
val=(val*10)+c-'0';
} while((c=gc()) && (c>='0' && c<='9'));
return val*(neg?-1:1);
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)
struct poss {
pair<ll,ll> val;
int L, R;
bool operator<(const poss& masik) const {
return val.xx*masik.val.yy<val.yy*masik.val.xx;
}
};
int main() {
IO;
int n;
cin>>n;
string t;
cin>>t;
vector<poss> lst;
for(int k=1;k<=26;++k) {
int L=0, R=-1;
map<char, int> van;
int ans=0, LL, RR;
while(R<n) {
if(sz(van)<=k) {
if(ans<R-L+1) {
ans=R-L+1;
LL=L;
RR=R;
}
van[t[++R]]++;
}else if(sz(van)>k) {
van[t[L]]--;
if(van[t[L]]==0) van.erase(t[L]);
L++;
}
}
if(ans>0) {
lst.push_back({mp(k,ans), LL, RR});
}
}
sort(lst.begin(), lst.end());
assert(lst.size()>0);
cout<<lst[0].L+1<<" "<<lst[0].R+1<<"\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... |