結果

問題 No.171 スワップ文字列(Med)
ユーザー msm1993msm1993
提出日時 2020-10-23 16:02:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 789 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 173,196 KB
実行使用メモリ 7,504 KB
最終ジャッジ日時 2023-09-28 15:33:54
合計ジャッジ時間 2,658 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,204 KB
testcase_01 AC 4 ms
7,360 KB
testcase_02 AC 5 ms
7,280 KB
testcase_03 AC 5 ms
7,360 KB
testcase_04 AC 5 ms
7,300 KB
testcase_05 AC 5 ms
7,504 KB
testcase_06 AC 6 ms
7,424 KB
testcase_07 AC 5 ms
7,432 KB
testcase_08 AC 7 ms
7,440 KB
testcase_09 AC 5 ms
7,324 KB
testcase_10 AC 5 ms
7,360 KB
testcase_11 AC 5 ms
7,264 KB
testcase_12 AC 5 ms
7,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int mod = 573;

int memo[1010][1010];
int C(int n, int k) {
    if (memo[n][k] != -1)
        return memo[n][k];
    if (n == 0) {
        return 1;
    }
    int ret = 0;
    if (k > 0)
        ret += C(n - 1, k - 1);
    if (k < n)
        ret += C(n - 1, k);
    return memo[n][k] = ret % mod;
}


int main() {
    string S;
    cin >> S;

    map<char, int> mp;
    for (auto& c : S) {
        mp[c]++;
    }

    for (int i = 0; i < 1001; i++) {
        for (int j = 0; j < 1001; j++) {
            memo[i][j] = -1;
        }
    }

    int ans = 1;
    int res = S.size();
    for (auto& p : mp) {
        (ans *= C(res, p.second)) %= mod;
        res -= p.second;
    }

    ((ans += mod) -= 1) %= mod;
    cout << ans << endl;
}
0