結果

問題 No.171 スワップ文字列(Med)
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-09-28 15:26:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 2,081 bytes
コンパイル時間 1,843 ms
コンパイル使用メモリ 164,244 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-10 06:50:18
合計ジャッジ時間 1,997 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 5 ms
7,552 KB
testcase_07 AC 7 ms
10,240 KB
testcase_08 AC 7 ms
11,136 KB
testcase_09 AC 8 ms
11,136 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

template<int mod>
struct mint {
private:
    ll x;
public:
    mint(ll x = 0) :x(x%mod) {}
    mint(string s) {
        ll z = 0;
        REP(i, s.size()) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    friend ostream& operator<<(ostream& os, const mint& n) {
        return os << n.x;
    }
    bool operator==(const mint a) const {
        return this->x == a.x;
    }
};

int main() {
    string s; cin >> s;
    int n = s.size();
    mint<573> ans = 1;
    vector<vector<mint<573>>> comb(n + 1, vector<mint<573>>(n + 1, 0));
    REP(i, n + 1) {
        comb[i][0] = 1;
        comb[i][i] = 1;
    }
    FOR(i, 1, n + 1) {
        FOR(j, 1, i) {
            comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
        }
    }
    /*
    REP(i, n + 1) {
        REP(j, n + 1) {
            cout << "comb[" << i << "][" << j << "] = " << comb[i][j] << endl;
        }
    }
    */
    vector<int> cnt(26, 0);
    REP(i, n) {
        cnt[s[i] - 'A']++;
    }
    REP(i, 26) {
        ans *= comb[n][cnt[i]];
        n -= cnt[i];
    }
    cout << ans - 1<< endl;
    return 0;
}
0