Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Seng
Problemset: ดีกค์เวิร์ด
Language: cpp
Time: 0.002 second
Submitted On: 2026-06-02 20:16:29
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
void rec(int x, int y, int a, int sum, char c1, char c2){
if(x > y) return;
//cout << x << " " << y << " " << a << " " << sum << " " << c1 << " " << c2 << '\n';
if(x == 0 && y == 0){
ans += sum;
return;
}
int add = (c1-'A'+1)*a;
if(x > 0) rec(x-1, y, a+1, sum+add, c1, c2);
add = (c2-'A'+1)*a;
if(y > 0) rec(x, y-1, a+1, sum+add, c1, c2);
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;cin >> n;
char a, b;cin >> a >> b;
//cout << n << ' ' << a << " " << b << '\n';
rec(n, n, 1, 0, a, b);
cout << ans;
}
// 2 X Y
// 3 B A