Submission

Status:
PPPPPPPPPP

Score: 100

User: meme_boi2

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

Language: cpp

Time: 0.023 second

Submitted On: 2025-03-31 12:47:43

#include <bits/stdc++.h>
using namespace std;
char a ,b;
long long n, cnt = 0; vector<string> use;
void gen(int cntA, int cntB,string txt){
    if(cntA > n || cntB > n) return;
    if(txt.length() == n << 1){
        use.push_back(txt);
        return;
    }
    if(cntA > cntB){
        gen(cntA,cntB+1,txt + b);
        gen(cntA+1,cntB,txt + a);
    }else{
        gen(cntA+1,cntB,txt+a);
    }
}

int32_t main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    cin >> n >> a >>b;
    gen(0,0,"");
    for(auto txt: use){
        for(int i = 0; i < n+n; i++){
            cnt += (i+1)*(txt[i]-'A'+1);
        }
    }
    cout << cnt;
}