이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int N,Ans;
string S;
int A[17];
bool Used[17];
int B[9][2];
bool g(int a,int b,int c,int d){
    if (a>b)
        swap(a,b);
    if (c>d)
        swap(c,d);
    if (a>c){
        swap(a,c);
        swap(b,d);
    }
    return c<b&&b<d;
}
void f(int t){
    int w=0;
    for (int i=1; i<=N*2; i++){
        if (!A[i]&&!Used[i]){
            w=i;
            break;
        }
    }
    if (!w){
        int tmp=0;
        for (int i=1; i<=N; i++){
            for (int j=i+1; j<=N; j++)
                tmp+=g(B[i][0],B[i][1],B[j][0],B[j][1]);
        }
        Ans=max(Ans,tmp);
        return;
    }
    Used[w]=true;
    B[t][0]=w;
    for (int i=1; i<=N*2; i++){
        if (A[i]&&!Used[i]){
            Used[i]=true;
            B[t][1]=i;
            f(t+1);
            Used[i]=false;
        }
    }
    Used[w]=false;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N>>S;
    for (int i=1; i<=N*2; i++)
        A[i]=(S[i-1]=='B');
    f(1);
    cout<<Ans;
    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... |