Submission
Status:
----------
Subtask/Task Score:
0/100
Score: 0
User: PIXIX
Problemset: ดีกค์เวิร์ด
Language: cpp
Time: 0.013 second
Submitted On: 2026-03-19 12:22:56
#include <algorithm>
#include <cstddef>
#include <ios>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
bool checkDyck(string &str,vector<char> &checker){
int state = 0;
for(char ch : str){
if(ch == checker[0]) state++;
else state--;
if(state < 0) return false;
}
return true;
}
int getWeight(string &str){
int n = str.size();
int total_w = 0;
for(int i = 0;i < n;i++){
total_w = total_w + (((int) str[i] - 'A' + 1) * (i + 1));
}
return total_w;
}
void gen(vector<char> &checker,string currstr,string size){}
int main (int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vector<char> checker(2);
cin >> checker[0] >> checker[1];
string input = "";
for(int i = 0;i < n;i++){
input += checker[0];
input += checker[1];
}
sort(input.begin(),input.end());
int total_w = 0;
do{
if(checkDyck(input, checker)){
cout << input << "\n";
total_w += getWeight(input);
}
} while(next_permutation(input.begin(),input.end()));
cout << total_w;
return 0;
}