結果

問題 No.171 スワップ文字列(Med)
ユーザー maine_honzukimaine_honzuki
提出日時 2020-06-05 16:08:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 789 bytes
コンパイル時間 1,624 ms
コンパイル使用メモリ 172,224 KB
実行使用メモリ 7,564 KB
最終ジャッジ日時 2023-08-22 06:14:36
合計ジャッジ時間 2,434 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,304 KB
testcase_01 AC 5 ms
7,308 KB
testcase_02 AC 5 ms
7,544 KB
testcase_03 AC 4 ms
7,272 KB
testcase_04 AC 5 ms
7,308 KB
testcase_05 AC 4 ms
7,444 KB
testcase_06 AC 6 ms
7,368 KB
testcase_07 AC 5 ms
7,564 KB
testcase_08 AC 7 ms
7,364 KB
testcase_09 AC 5 ms
7,444 KB
testcase_10 AC 4 ms
7,280 KB
testcase_11 AC 5 ms
7,356 KB
testcase_12 AC 4 ms
7,280 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