Submission
Status:
PPPPPPPTPTPPPPPPPPPP
Subtask/Task Score:
90/100
Score: 90
User: dddrrrr
Problemset: สุ่มสลับ
Language: cpp
Time: 0.197 second
Submitted On: 2025-10-14 11:00:20
#include <bits/stdc++.h>
using namespace std;
string s;
int cnt = 0;
bool found = false;
void backtrack(string& str ,string& tmp ,vector <bool>& chosen){
if(found)return ;
if(tmp.size() == str.size()){
cnt++;
if(tmp == s){
cout << cnt;
found = true;
}
return ;
}
for(int i=0 ;i<str.size() ;i++){
if(chosen[i])continue;
tmp += str[i];
chosen[i] = true;
backtrack(str ,tmp ,chosen);
tmp.pop_back();
chosen[i] = false;
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int n;cin >> n;
string str ;cin >> str;
s = str;
sort(str.begin() ,str.end());
vector <bool> chosen(str.size() ,false);
string tmp="";
backtrack(str ,tmp ,chosen);
return 0;
}