Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Fifaxmb
Problemset: ดีกค์เวิร์ด
Language: cpp
Time: 0.011 second
Submitted On: 2026-05-23 12:31:51
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define Fifa67king ios::sync_with_stdio(0);cin.tie(0);
int n;
i64 ans = 0;
string str = "";
void solve(string str){
int sz = str.size();
for(int i = 0;i < sz;i++){
ans += (i + 1)* (str[i] - 'A' + 1);
}
// cout << ans << '\n';
return;
}
void rec(char a,char b,int sza ,int szb){
if(sza + szb == 2 * n){
if(sza == 0 || szb == 0 || sza < n || szb < n) return;
// cout << str << '\n';
solve(str);
return;
}
if(szb > sza) return;
str.push_back(a);
rec(a,b,sza + 1,szb);
str.pop_back();
str.push_back(b);
rec(a,b,sza,szb + 1);
str.pop_back();
}
int main(){
Fifa67king;
cin >> n;
char a,b;cin >> a >> b;
rec(a,b,0,0);
cout << ans;
// cout << 'Z' - 'A';
}