Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Nathako9n

Problemset: ดีกค์เวิร์ด

Language: cpp

Time: 0.010 second

Submitted On: 2026-01-18 14:01:26

#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
int n;
const int N = 12;
char a,b;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>a>>b;
    n+=n;
    ll ans=0;
    for(int i=0;i<(1<<n);i++){
        int x=0,y=0;
        ll sum=0;
        bool ok=1;
        if(__builtin_popcount(i)!=n/2)continue;
        for(int j=0;j<n;j++){
            if(i&(1<<j)){
                if(y>++x){ok=0;break;}
                sum+=((a-'A')+1)*(j+1);
                //cout<<((a-'A')+1)*(j+1)<<endl;
            }
            else{
                if(++y>x){ok=0;break;}
                sum+=((b-'A')+1)*(j+1);
                //cout<<((b-'A')+1)*(j+1)<<endl;
            }

        }
        if(ok)ans+=sum;
     //   cout<<endl;
    }
    cout<<ans;
    cout<<endl;
   // cout<<b-'A';
    return 0;
}

/*

2
X
Y


3
B
A




*/