# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844578 | vjudge1 | Nivelle (COCI20_nivelle) | C++17 | 182 ms | 852 KiB |
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 int long long
using namespace std;
int32_t main(){
int n;cin>>n;
string str;cin>>str;
vector<int> ilk(26,-1);
vector<int> son(26,-1);
for (int i = 0; i < n; i++){
if (ilk[str[i]-'a']==-1) ilk[str[i]-'a']=i;
son[str[i]-'a']=i;
}
vector<int> ls;
vector<int> rs;
for (int i = 0; i < 26; i++){
if (son[i]==-1) continue;
ls.push_back(son[i]+1);
ls.push_back(ilk[i]);
rs.push_back(ilk[i]-1);
rs.push_back(son[i]);
}
vector<bool> vis(26,true);
int frac1 = 1;
int frac2 = 1;
sort(ls.begin(), ls.end());
sort(rs.begin(), rs.end());
int ansl=0, ansr=0;
for (int ll = 0; ll < ls.size(); ll++){
for (int rr = 0; rr < rs.size(); rr++){
int l = ls[ll];
int r = rs[rr];
if (l>r) continue;
fill(vis.begin(), vis.end(), 0);
int crr = 0;
for (int i = l; i <= r; i++){
if (!vis[str[i]-'a']) crr++;
vis[str[i]-'a']=true;
}
if (crr*frac2<(r-l+1)*frac1){
frac1=crr;
frac2=(r-l+1);
ansl=l;
ansr=r;
}
}
}
cout<<ansl+1<<" "<<ansr+1<<endl;
}
Compilation message (stderr)
# | 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... |