이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll check(vector<char>v){
int n = v.size() - 1;
bool M, B, F;
M = B = F = 0;
for(int i = 0; i < 3; i++){
if(v[n - i] == 'M') M = true;
else if(v[n - i] == 'B') B = true;
else if(v[n - i] == 'F') F = true;
}
return (M + B + F);
}
int main(){
int n; cin >> n;
ll ans = 0;
vector<char>s(n);
for(int i = 1; i <= n; i++) cin >> s[i];
vector<char>a, b;
a.push_back('A');
a.push_back('A');
b.push_back('A');
b.push_back('A');
for(int i = 1; i <= n; i++){
bool x, y;
x = y = false;
if(s[i] != a.back() && s[i] == b.back()){
a.push_back(s[i]);
x = true;
} else if(s[i] != b.back() && s[i] == a.back()){
b.push_back(s[i]);
y = true;
} else if(s[i] != a.back() && s[i] != b.back()){
auto it1 = find(s.begin() + i, s.end(), a.back()) - s.begin();
auto it2 = find(s.begin() + i, s.end(), b.back()) - s.begin();
if(it1 < it2){
a.push_back(s[i]);
x = true;
}
else{
b.push_back(s[i]);
y = true;
}
} else{
vector<char>tmpa, tmpb;
tmpa = a;
tmpb = b;
tmpa.push_back(s[i]);
tmpb.push_back(s[i]);
if(check(tmpa) > check(tmpb)){
a.push_back(s[i]);
x = true;
} else{
b.push_back(s[i]);
y = true;
}
}
if(x) ans += check(a);
else ans += check(b);
}
cout << ans << endl;
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... |