Submission

Status:

PPPPPPPPPPPPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: erng

Problemset: สุ่มสลับ

Language: cpp

Time: 0.003 second

Submitted On: 2025-10-10 23:05:20

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

string s;
unsigned long long ans;
int n;

int fac(int x)
{
    if (x==0) return 1;
    else return x*fac(x-1);
}

int main()
{
    cin>>n>>s;
    for (int i=0; i<n; i++)
    {
        ans+=(s[i]-'A')*(fac(n-i-1));
        for (int j=i+1; j<n; j++)
        {
            if (s[j]>s[i]) s[j]--;
        }
    }
    cout<<ans+1;
}