結果

問題 No.171 スワップ文字列(Med)
ユーザー なおなお
提出日時 2015-02-22 09:40:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 1,000 ms
コード長 1,011 bytes
コンパイル時間 1,309 ms
コンパイル使用メモリ 150,468 KB
実行使用メモリ 5,396 KB
最終ジャッジ日時 2023-09-06 02:56:50
合計ジャッジ時間 2,267 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,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,532 KB
testcase_07 AC 5 ms
5,148 KB
testcase_08 AC 4 ms
5,364 KB
testcase_09 AC 4 ms
5,396 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 想定解: 組み合わせ
// 事前計算O(max(|S|)^2) 入力処理O(|S|+T), T=文字の種類(26)
#include <bits/stdc++.h>
using namespace std;
template<typename _T> void rc(_T v,_T mn,_T mx){if(v<mn||mx<v){cerr<<"error"<<endl;throw;}}
const int MOD = 573;

// nCm MOD
int combination_mod(int n, int m){
    static vector<vector<int> >c;static int maxn;
    if(n<0||m<0||n<m)return 0;m=min(m,n-m);
    if(n>maxn){c.resize(n+1);for(int i=maxn;i<=n;i++)c[i].resize(i+1);c[0][0]=1;for(int i=maxn+1;i<=n;i++){
    for(int j=1;j<i;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;c[i][0]=c[i][i]=1;}maxn=n;}
    return c[n][m];
}

int s[256];

int main(){
    string S; cin >> S;
    rc((int)S.size(), 1, 1000);
    for(const auto &c : S) rc(c, 'A', 'Z');

    for(const auto &c : S) s[c]++;
    int n = S.size();
    int res = 1;
    for(int i = 'A'; i <= 'Z'; i++){
        (res *= combination_mod(n, s[i])) %= MOD;
        n -= s[i];
    }

    // (res-1) % MOD
    (res += MOD-1) %= MOD;

    cout << res << endl;
}
0