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;
int n,i,j,k,a1,a2,a3,b1,b2,b3,cnt,ans,x[100005];
string s;
int main(){
cin >> n >> s;
for(i=0;i<n;i++){
if(s[i]=='M') x[i]=1;
if(s[i]=='F') x[i]=2;
if(s[i]=='B') x[i]=3;
}
for(i=0;i<(1<<(n-1));i++){
cnt=0;
a1=0;a2=0;a3=0;b1=0;b2=0;b3=0;
for(j=0;j<n;j++){
if(i&(1<<j)){
a3=a2;
a2=a1;
a1=x[j];
for(k=1;k<=3;k++){
if(a1==k || a2==k || a3==k) cnt++;
}
}
else{
b3=b2;
b2=b1;
b1=x[j];
for(k=1;k<=3;k++){
if(b1==k || b2==k || b3==k) cnt++;
}
}
}
ans=max(ans,cnt);
}
cout << ans;
}
# | 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... |