結果

問題 No.171 スワップ文字列(Med)
ユーザー face4face4
提出日時 2018-09-26 15:06:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 1,042 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 73,520 KB
実行使用メモリ 7,584 KB
最終ジャッジ日時 2023-08-01 04:34:23
合計ジャッジ時間 1,557 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 3 ms
4,760 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 4 ms
5,564 KB
testcase_07 AC 5 ms
6,876 KB
testcase_08 AC 6 ms
7,360 KB
testcase_09 AC 6 ms
7,584 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

const int mod = 573;

struct Combination{
    int n;
    vector<vector<int>> dp;

    Combination(int i){
        n = i;
        dp = vector<vector<int>>(n+1, vector<int>(n+1, 0));
        constructTriangle();
    }

    void constructTriangle(){
        dp[0][0] = 1;
        for(int i = 1; i <= n; i++){
            dp[i][0] = dp[i-1][0];
            for(int j = 1; j <= i; j++){
                dp[i][j] = (dp[i-1][j] + dp[i-1][j-1])%mod;
            }
        }
    }

    // return aCb
    int getCombination(int a, int b){
        return dp[a][b];
    }
};

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

    int n = s.length();
    Combination c(n);
    int appear[26] = {};

    for(int i = 0; i < n; i++)  appear[s[i]-'A']++;

    long long ans = 1;
    for(int i = 0; i < 26; i++){
        if(appear[i]){
            ans *= c.getCombination(n, appear[i]);
            ans %= mod;
            n -= appear[i];
        }
    }

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

    return 0;
}
0