結果

問題 No.171 スワップ文字列(Med)
ユーザー xuzijian629xuzijian629
提出日時 2018-11-02 21:00:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 1,416 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 210,844 KB
実行使用メモリ 11,160 KB
最終ジャッジ日時 2023-08-12 22:35:10
合計ジャッジ時間 3,507 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
10,944 KB
testcase_01 AC 8 ms
10,900 KB
testcase_02 AC 9 ms
10,972 KB
testcase_03 AC 9 ms
10,924 KB
testcase_04 AC 8 ms
10,848 KB
testcase_05 AC 8 ms
10,968 KB
testcase_06 AC 8 ms
10,880 KB
testcase_07 AC 9 ms
11,052 KB
testcase_08 AC 8 ms
10,892 KB
testcase_09 AC 9 ms
10,876 KB
testcase_10 AC 9 ms
10,972 KB
testcase_11 AC 8 ms
11,160 KB
testcase_12 AC 9 ms
10,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
constexpr i64 MOD = 573;

struct Combination {
    int n;
    vvi dp;
    Combination(int n) : n(n) {}
    
    void build() {
        dp = vvi(n + 1, vi(n + 1));
        for (int i = 0; i <= n; i++) {
            dp[i][0] = 1;
            dp[i][i] = 1;
        }
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j < i; j++) {
                dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
                dp[i][j] %= MOD;
            }
        }
    }
    
    i64 built_ncr(int n, int r) {
        return dp[n][r];
    }
    
    // avoid MLE
    i64 ncr(int n, int r) {
        if (n < 2) return 1;
        vi cur(2, 1);
        for (int i = 2; i <= n; i++) {
            vi nex(n + 1, 1);
            for (int j = 1; j < i; j++) {
                nex[j] = cur[j - 1] + cur[j];
                nex[j] %= MOD;
            }
            cur = move(nex);
        }
        return cur[r];
    }
};

int main() {
    string s;
    cin >> s;
    Combination comb(1000);
    comb.build();

    map<char, int> cnt;
    for (char c: s) {
        cnt[c]++;
    }

    i64 ans = 1;
    int tot = s.size();
    for (auto& p: cnt) {
        ans *= comb.built_ncr(tot, p.second);
        ans %= MOD;
        tot -= p.second;
    }
    assert(tot == 0);
    cout << (ans - 1 + MOD) % MOD << endl;
}
0