結果

問題 No.170 スワップ文字列(Easy)
ユーザー maine_honzukimaine_honzuki
提出日時 2020-06-05 16:08:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 789 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 171,580 KB
実行使用メモリ 7,572 KB
最終ジャッジ日時 2023-08-22 06:14:59
合計ジャッジ時間 3,211 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,272 KB
testcase_01 AC 4 ms
7,336 KB
testcase_02 AC 5 ms
7,304 KB
testcase_03 AC 4 ms
7,352 KB
testcase_04 AC 5 ms
7,276 KB
testcase_05 AC 4 ms
7,348 KB
testcase_06 AC 5 ms
7,352 KB
testcase_07 AC 4 ms
7,300 KB
testcase_08 AC 4 ms
7,332 KB
testcase_09 AC 4 ms
7,556 KB
testcase_10 AC 4 ms
7,336 KB
testcase_11 AC 4 ms
7,284 KB
testcase_12 AC 4 ms
7,572 KB
testcase_13 AC 4 ms
7,556 KB
testcase_14 AC 4 ms
7,288 KB
testcase_15 AC 5 ms
7,300 KB
testcase_16 AC 4 ms
7,344 KB
testcase_17 AC 5 ms
7,272 KB
testcase_18 AC 4 ms
7,280 KB
testcase_19 AC 4 ms
7,328 KB
testcase_20 AC 4 ms
7,300 KB
testcase_21 AC 4 ms
7,372 KB
testcase_22 AC 4 ms
7,300 KB
testcase_23 AC 4 ms
7,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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