Submission

Status:

PPPPPPPPPPPPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: pann

Problemset: สุ่มสลับ

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-12 20:57:09

#include <iostream>
#include <algorithm>
using namespace std;

int fact(int x){
    if (x == 0 || x == 1) return 1;
    return x * fact(x-1);
}

int main(){
    int n;
    cin >> n;
    string s,sorted_s;
    cin >> s;
    sorted_s = s;
    int ans = 1;
    sort(sorted_s.begin(), sorted_s.end());
    int x = fact(s.length()-1);
    for (int i = 0; i < s.length()-1; i++){
        ans += (sorted_s.find(s[i]))*x;
            sorted_s.erase(sorted_s.find(s[i]), 1);
            x /= sorted_s.length();
    }
    cout << ans;
    return 0;
}