結果
| 問題 | No.171 スワップ文字列(Med) | 
| コンテスト | |
| ユーザー |  xuzijian629 | 
| 提出日時 | 2018-11-02 21:00:51 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 10 ms / 1,000 ms | 
| コード長 | 1,416 bytes | 
| コンパイル時間 | 2,255 ms | 
| コンパイル使用メモリ | 206,276 KB | 
| 最終ジャッジ日時 | 2025-01-06 15:27:17 | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 | 
ソースコード
#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;
}
            
            
            
        