CSES Creating Strings
// compile: g++ -o data data.cpp -std=gnu++20 -DLOCAL
// run: ./data < data.in
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef LOCAL
#endif
#define sz(v) ((int)(v).size())
#define PV(v) for (int i=0;i<v.size();++i)cout<<v[i]<<" ";cout<<endl;
#define INTINF 9223372036854775807
#define int long long
#define MAXN 20000010

using namespace std;

string s;
int n;
int p[30], vis[30];
int fact[30];
vector<string> f;

void check() {
    string str = "";
    for (int i = 0; i < n; ++i) str += s[p[i]];
    f.push_back(str);
}

void dfs(int k) {
    if (k >= n) {
        check();
        return;
    }
    for (int i = 0; i < n; ++i) {
        if (vis[i]) continue;
        vis[i] = 1;
        p[k] = i;
        dfs(k + 1);
        vis[i] = 0;
    }
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int fact[20]; fact[0] = 1;
    for (int i = 1; i < 10; ++i) fact[i] = fact[i-1] * i;
    cin >> s;
    n = s.length();
    int ans = fact[n];
    int cnt[30]; memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; ++i) ++cnt[s[i]-'a'];
    for (int i = 0; i < 26; ++i) ans /= fact[cnt[i]];
    f.clear();
    dfs(0);
    sort(f.begin(), f.end());
    cout << ans << endl;
    cout << f[0] << endl;
    for (int i = 1; i < sz(f); ++i) {
        if (f[i] == f[i-1]) continue;
        cout << f[i] << endl;
    }

    return 0;
}
No Comments

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous
Next