結果

問題 No.171 スワップ文字列(Med)
ユーザー tottoripapertottoripaper
提出日時 2015-03-22 23:43:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,421 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 54,592 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-11 09:35:31
合計ジャッジ時間 1,188 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// Wrongri-La Shower

#include <cstdio>
#include <iostream>

typedef std::tuple<int,int,int> T;
typedef long long ll;
// 573: 3 191

int count[26], inv[573];

int mod_pow(int a, int n){
    int res = 1;
    while(n > 0){
        if(n & 1){res = res * a % 573;}
        n >>= 1;
        a = a * a % 573;
    }
    return res;
}

int nCk(int n, int k){
    if(n < k){return 0ll;}
    
    int n3 = 0, n191 = 0, other = 1;
    for(int i=n-k+1;i<=n;i++){
        
        int x = i;
        while(x % 3 == 0){
            ++n3; x /= 3;
        }
        while(x % 191 == 0){
            ++n191; x /= 191;
        }
        other = other * x % 573;
    }

    int other2 = 1;
    for(int i=1;i<=k;i++){
        int x = i;
        while(x % 3 == 0){
            --n3; x /= 3;
        }
        while(x % 191 == 0){
            --n191; x /= 191;
        }
        other2 = other2 * x % 573;        
    }

    return mod_pow(3, n3) * mod_pow(191, n191) % 573 * other % 573 * inv[other2] % 573;
}

int main(){
    for(int i=0;i<573;i++){
        for(int j=0;j<573;j++){
            if(i * j % 573 == 1){inv[i] = j; break;}
        }
    }
    
    std::string S;
    std::cin >> S;

    for(char c : S){
        count[c-'A'] += 1;
    }

    int res = 1ll;
    int sum = 0;
    for(int i=0;i<26;i++){
        res = res * nCk(S.size()-sum, count[i]) % 573;
        sum += count[i];
    }

    printf("%d\n", (res+573-1) % 573);
}
0