Problem:
Sort Riddles
A sort riddle is a game in which you guess the original English word from a string of letters in an English word, rearranged in alphabetical order.
For example, if you are given the string
aet
, you can guess that the original English word was
eat
,
ate
, and so on.
To play this game, PCK, who is not good at English words, decided to think of the given string and all the strings that are rearranged.
Given a rearranged string, write a program to output the number of strings that PCK will consider.
Input
The input is given in the following format.
$str$
A string $str$ rearranged into a single line is given.  $str$ contains only lowercase letters, and its length is between 1 and 8. Also, each character is arranged in alphabetical order from the beginning.
Output
Output the number of strings that PCK will think about.
Sample Input and Output
Sample Input 1
aet
Sample Output 1
6
Sample Input 2
eeei
Sample Output 2
4

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
	int cnt=0;
	string str;
	map<string,int> mp;
	cin>>str;
	do{
		if(mp[str]==0){
			cnt++;
			mp[str]=1;
		}
	}while(next_permutation(str.begin(),str.end()));
	cout<<cnt<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6504
final_rank: 3

code_snippet: //kouu42ga8
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int i,cnt=0;
	string s;
	map<string,int> mp;
	cin>>s;
	do{
		if(mp[s]==0){
			cnt++;
			mp[s]=1;
		}
	}while(next_permutation(s.begin(),s.end()));
	cout<<cnt<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6596
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF INT64_MAX;
map<string,bool> mp;
int main(void)
{
    LL cnt=0;
    string s;
    cin>>s;
    do{
        if(!mp[s]) cnt++,mp[s]=true;
    }while(next_permutation(s.begin(),s.end()));
    cout<<cnt<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 7548
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ll long long
#define ptn(v) next_permutation(v.begin(), v.end())
#define fixed(v) fixed << setprecision(v)
#define total(n) ((n) * ((n) + 1) / 2)
#define combi(n) ((n) * ((n)-1) / 2) // n個の数の組み合わせ数
#define lcm(a, b) ((a) * (b) / __gcd(a, b))
// binery_search(all(v),key) = keyがあるかないかをboolで返す
// lower_bound(all(v),key) = key以上のイテレーターを返す(一番左)
// upper_bound(all(v),key) = keyより大きい要素のイテレーターを返す
// 最小値＝max_element(v.begin(),v.end());
// 最大値＝min_element(v.begin(),v.end());

template <class x>
x rng_total(x l, x r)
{ // l ~ rまでの数の総和
    return ((l + r) * (r - l + 1) / 2);
}

template <class x>
x rng_combi(x l, x r)
{ //「n個の物からr個取った組み合わせ数」
    x ans = 1;
    l++;
    for (x i = 1; i <= r; i++)
    {
        x sub = l - i;
        ans *= sub;
        ans /= i;
    }
    return (ans);
}

template <class x>
x dig_sum(x num)
{ // 各桁の総和
    x ans = 0;
    while (num > 0)
    {
        ans += num % 10;
        num /= 10;
    }
    return (ans);
}

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

    //-----------------------------------------------------

    string s;
    cin >> s;
    set<string> st;
    sort(all(s));
    do {
        if (!st.count(s)) {
            st.insert(s);
        }
    } while (ptn(s));
    cout << st.size() << endl;

    return (0);
}
accuracy: 1
time_ms: 10
memory_kb: 6596
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

void permutations(const string& s, string& v, vector<bool>& b, set<string>& p) {
    if (v.length() == s.length()) {
        p.insert(v);
    }
    else {
        for (int i = 0; i < (int)s.length(); ++i) {
            if (!b[i]) {
                v += s[i];
                b[i] = true;
                permutations(s, v, b, p);
                b[i] = false;
                v.pop_back();
            }
        }
    }
}
int main() {
    string s;
    cin >> s;
    vector<bool> b(s.length(), false);
    set<string> p;
    string v = "";
    permutations(s, v, b, p);
    cout << p.size() << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6292
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    int count=0;
    string str;cin>>str;
    map<string,bool>mp;
    sort(str.begin(),str.end());
    do
    {
       if(mp[str]==false){
            count++;
            mp[str]=true;
       }
    } while (next_permutation(str.begin(),str.end()));
    cout<<count<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 6480
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define INF 2047483647 //大きすぎる可能性有り
#define ll long long

int main(){
    string str; cin>>str;
    int kaisu=0;
    sort(str.begin(),str.end());
    map<string,bool> mp;
    int count=0;
    do{ 
        if(mp[str]==false){ count++; mp[str]=true;}
    }while(next_permutation(str.begin(),str.end()));
    cout<<count<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 7572
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
class extension {
//イテレーター省略
#define all(v) v.begin(),v.end()
//配列の読み取り
#define loadVector(n,v) for (int i = 0;i < n;i++) cin >> v[i]
//pair型配列の読み取り
#define loadVectors(n,v) for (int i = 0;i < n;i++) cin >> v[i].first >> v[i].second
//逆ソート
#define r_sort(v) sort(v.rbegin(),v.rend())
//long long省略
#define ll long long
//指定したkeyがmapに存在するかどうか
#define mapFind(m,x) m.find(x) != end(m)
//long doubleの省略
#define ld long double
//unsigned long longの省略
#define ull unsigned long long
//priority_queueの省略
#define pq priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>

//nをbase_number進数に変換する
public:string To_oct(int n, int base_number) {
    string s;
    while (n) {
        s = to_string(n % base_number) + s;
        n /= base_number;
    }
    return s;
}

//エラトステネスの篩
vector<int> Eratosthenes(int N) {
    vector<bool> is_prime(N + 1);
    for (int i = 0; i <= N; i++) is_prime[i] = true;
    vector<int> P;
    for (int i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (int j = 2 * i; j <= N; j += i)
            {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

//文字列を分割する
vector<string> Split(const string& str, char sep) {
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while(getline(ss, buffer, sep)) {
        v.push_back(buffer);
    }
    return v;
}

//約数全列挙
vector<ll> Divisor(ll n) {
    vector<ll> result;
    set<ll> s;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            s.insert(i);
            s.insert(n / i);
        }
    }

    for (int x : s) {
        result.push_back(x);
    }
    return result;
}

//連立方程式を解く
pair<int,int> SimultaneousEquations(int a,int b,int c,int d,int e,int f) {
    double matrix;
	matrix = a * e - b*d;

	double x, y;
	if (matrix == 0) {
		cout << "連立方程式の解はありません\n";
		return make_pair(-1,-1);
	}
	else {
		x = (c * e - b * f) / matrix;
		y = (a * f - c * d) / matrix;
		
		if (floor(x) != x || floor(y) != y) return make_pair(-1,-1);
		return make_pair(x,y);
	}
}

//コンビネーション(nCr)
unsigned long long Combination(int n, int r)
{
    if (n < 0 || r < 0 || r > n) cout << "無効な値です" << endl;

    if (n - r < r) r = n - r;
    if (r == 0) return 1;
    if (r == 1) return n;

    vector<int> numerator(r);
    vector<int> denominator(r);

    for (int k = 0; k < r; k++)
    {
        numerator[k] = n - r + k + 1;
        denominator[k] = k + 1;
    }

    for (int p = 2; p <= r; p++)
    {
        int pivot = denominator[p - 1];
        if (pivot > 1)
        {
            int offset = (n - r) % p;
            for (int k = p - 1; k < r; k += p)
            {
                numerator[k - offset] /= pivot;
                denominator[k] /= pivot;
            }
        }
    }

    unsigned long long result = 1;
    for (int k = 0; k < r; k++)
    {
        if (numerator[k] > 1) result *= numerator[k];
    }

    return result;
}

//二分探索
int Binary_Search(vector<int> _x,int key) {
    int left = -1,right = _x.size();
    
    while (right - left > 1) {
        int mid = (left+right) / 2;
        
        if (_x[mid] >= key) right = mid;
        else left = mid;
    }
    
    return right;
}

//ワ―シャルフロイド法
void Floyd_warshall(vector<vector<int>>& g,int vertexCnt) {
    for (int i = 0;i < vertexCnt;i++) {
        for (int j = 0;j < vertexCnt;j++) {
            for (int k = 0;k < vertexCnt;k++) {
                if (g[j][i] == 1e9 || g[i][k] == 1e9) continue;
                g[j][k] = min(g[j][k],g[j][i]+g[i][k]);
            }
        }
    }
}

// 第一引数と第二引数を比較し、第一引数(a)をより大きい/小さい値に上書き
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}

//配列の出力
template <typename T> inline void print(const vector<T>& v, string s = " ")
    {for (int i = 0;i < v.size();i++) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
//pairの出力
template <typename T, typename S> inline void print(const pair<T, S>& p)
    {cout << p.first << " " << p.second << endl;}
//普通の出力
template <typename T> inline void print(const T& x) {cout << x << "\n";}
//pair型配列の出力
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v)
    {for (auto&& p : v) print(p);}
};

class Mathf {
    public:
    template <typename T> inline T clamp(const T& a,const T& b,const T& c) {
        if (a < b) return b;
        if (a > c) return c;
        return a;
    }
    template <typename T> inline T clamp01(const T& a) {
        if (a < 0) return 0;
        if (a > 1) return 1;
        return a;
    }
    template <typename T> inline void lerp(T& a) {
        T _min = log2(a);
        cout << _min << endl;
    }
    //度からラジアン角
    const long double deg2rad = 0.0174532925199432954743716805979;
    //ラジアン角から度
    const long double rad2deg = 57.2957795130823228646477218717;
    //円周率
    const long double pi = M_PI;
};

set<string> anses;
void dfs(string a,map<char,int> b) {
    bool check = true;
    
    for (auto x : b) {
        if (x.second != 0) check = false;
    }
    
    if (check) {
        anses.insert(a);
        return;
    }
    
    map<char,int> c;
    for (auto x : b) {
        c[x.first] = x.second;
    }
    
    for (auto x : c) {
        if (x.second == 0) continue;
        
        c[x.first]--;
        dfs(a + x.first,c);
        
        c[x.first]++;
    }
}

int main(void) {
    // Your code here!
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
 
    //拡張クラスのインスタンス化
    extension ex = extension();
    Mathf mathf = Mathf();
    
    ////////ここから処理内容記述/////////////
    string s;
    cin >> s;
    
    map<char,int> m;
    for (int i = 0;i < s.length();i++) m[s[i]]++;
    
    dfs("",m);
    
    ex.print(anses.size());
}
accuracy: 1
time_ms: 40
memory_kb: 6512
final_rank: 9

code_snippet: //#ifdef DEBUG
#define _GLIBCXX_DEBUG
//#endif
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>
#include<limits>//
#include <stdio.h>//
#include<cmath>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>
#include <unordered_map>
//#include <windows.h>
//#include <stdlib.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
double pie = 3.14159265358979323846264338;
\
ll updiv(ll a, ll b){
  return ((a + b - 1) / b);
}

//using mint = modint998244353;
//using mint = modint1000000007;

bool Pn (int a){
  if (a == 1){
    return (false);
  }

  if (a == 2){
    return (true);
  }

  if (a % 2 == 0){
    return (false);
  }
  
  
  int n = sqrt(a);

  for (int i = 3; i <= n; i+=2){
    if (a % i == 0){
      return (false);
    }    
  }
  return (true);
}

bool PrimeNumber (int a){
  if (a == 1){
    return (false);
  }
  if (a == 2){
    return (true);
  }  
  if (a % 2 == 0){
    return (false);
  }

  int m = sqrt(a);

  for (int i = 0; i <= m; i++){
    if (a % i == 0){
      return (false);
    }    
  }
  return (true);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;
  int n = s.size(),cnt = 0;
  vector<int> a(n);
  map<string,int> mp;

  for (int i = 0; i < n; i++){
    a[i] = i;
  }
  

  do{
    string t;
    for (int i = 0; i < n; i++){
      t.push_back(s[a[i]]);
    }
    
    if (mp[t] == 0){
      mp[t] = 1;
      cnt++;
    }
    
      
  } while (next_permutation(a.begin(),a.end()));
  
  cout << cnt << '\n';

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 6616
final_rank: 6