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;
#define ll long long
#define pb push_back
int n;
void solve(){
cin >> n;
string s;
cin >> s;
int ans = 0;
vector<int> minea, mineb;
for(int i=0;i<n;i++){
set<char> a, b;
a.insert(s[i]);
if(minea.size())a.insert(minea.back());
if(minea.size() > 1)a.insert(*prev(prev(minea.end())));
b.insert(s[i]);
if(mineb.size())b.insert(mineb.back());
if(mineb.size() > 1)b.insert(*prev(prev(mineb.end())));
if(a.size() == b.size()){
if(minea.size() < mineb.size()){
minea.pb(s[i]);
} else {
mineb.pb(s[i]);
}
}
else if(a.size() > b.size()){
minea.pb(s[i]);
//cout<<"a";
} else {mineb.pb(s[i]);}//cout<<"b";}
ans += max(a.size(), b.size());
}
cout<<"\n";
cout<<ans<<"\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin>>t;
while(t--){
solve();
}
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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |