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