Submission

Status:

PPPPPPPPPPPPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Kidmaiok

Problemset: สุ่มสลับ

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-12 01:28:24

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define space << ' '
#define nl << endl

int factorial(int n){
    int fac = 1;
    for(int i =1; i <= n; i++){
        fac *= i;
    }
    return fac;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,ans = 1;
    bool use[12] = {};
    string x;
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        int current = x[i] - 'A';
        int smaller = 0;

        for (int j = 0; j < current; j++) {
            if (!use[j]) {
                smaller++;
            }
        }

        ans += smaller * factorial(n - i - 1);
        use[current] = true;
    }

    cout << ans << '\n';
}