Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: MoreCookies

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

Language: cpp

Time: 0.031 second

Submitted On: 2026-02-24 19:42:44

#include<bits/stdc++.h>
using namespace std;

int main(){
    int n, total=0;
    char c1, c2;
    cin >> n >> c1 >> c2;
    vector<char> word;
    for(int i=0; i<n; i++){
        word.push_back(c1);
        word.push_back(c2);
    }
    sort(word.begin(), word.end());
    do{
        int one=0, two=0;
        bool valid = true;
        for(int i=0; i<2*n; i++){
            if(word[i] == c1){
                one++;
            }else two++;

            if(two>one){
                valid = false;
            }
        }
        if(valid){
            for(int i=0; i<2*n; i++){
                total+=(word[i]-64)*(i+1);
            }
        }
    }while(next_permutation(word.begin(), word.end()));
    cout << total;
}