이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |