Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: devilpoohs

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

Language: cpp

Time: 0.016 second

Submitted On: 2026-03-08 15:23:10

#include<bits/stdc++.h>
using namespace std;
char a,b;
string s="";
int n;
int sum=0;
void think(int i,int j){
    if(i==0 and j==0){
        // cout<<s;
        for(int r=0;r<2*n;r++){
            sum+=((s[r]-'A'+1)*(r+1));
        }
        // cout<<'\n';
        return ;
    }
    if(i<=j-1){
        s=s+b;
        think(i,j-1);
        s.erase(s.end()-1);
    }
    
    if(i-1>=0){
        s=s+a;
        think(i-1,j);
        s.erase(s.end()-1);
    }
   
}

int main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);

    cin>>n>>a>>b;
    think(n,n);
    cout<<sum;
    return 0;
}