Submission

Status:
-------TTTT

Score: 0

User: devilpoohs

Problemset: ฝุ่นธุลีล้อมดาว

Language: cpp

Time: 1.092 second

Submitted On: 2024-12-18 19:43:05

#include<bits/stdc++.h>
using namespace std;
string ans;
int n;
int dp[12]={1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600};
bool chk(vector<char> str){
	for(int i=0;i<n;i++){
		if(str[i]!=ans[i]){
			return false ;
		}
	}
	return true ;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	cin>>ans ;
	vector<char> str(n) ;
	for(int i=0;i<n;i++){
		str[i]+=('A'+i) ;
	//	cout << str[i];
	}
	for(int i=ans[0]-'A';i>0;i--){
		swap(str[i],str[i-1]);
	}
//	for(int i=0;i<n;i++){
//
//		cout << str[i];
//	}
	int count=(dp[n-2]*(ans[0]-'A')) ;
	do{
		count++ ;
		if(chk(str)){
			cout << count ;
			break ;
		}
	}while(next_permutation(str.begin(),str.end()));
	return 0;
}