Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Kx
Problemset: ดีกค์เวิร์ด
Language: cpp
Time: 0.016 second
Submitted On: 2026-03-18 15:50:25
#include <bits/stdc++.h>
using namespace std;
int n;
char c1, c2;
int res = 0;
void dw(string s, int cnt_c1, int cnt_c2) {
if(s.length() == 2*n) {
for(int i = 0; i < 2*n; ++i) {
res += ((s[i] - 'A' + 1) * (i + 1));
}
return;
}
if(cnt_c1 == n) {
dw(s + c2, cnt_c1, cnt_c2 + 1);
return;
}
if(cnt_c1 >= cnt_c2) {
dw(s + c1, cnt_c1 + 1, cnt_c2);
dw(s + c2, cnt_c1, cnt_c2 + 1);
} else {
return;
}
}
int main() {
cin >> n >> c1 >> c2;
string s = "";
dw(s + c1, 1, 0);
cout << res << '\n';
return 0;
}