結果
| 問題 | No.171 スワップ文字列(Med) | 
| コンテスト | |
| ユーザー |  purple_jwl | 
| 提出日時 | 2015-03-22 23:47:27 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 10 ms / 1,000 ms | 
| コード長 | 1,054 bytes | 
| コンパイル時間 | 2,064 ms | 
| コンパイル使用メモリ | 164,476 KB | 
| 実行使用メモリ | 11,264 KB | 
| 最終ジャッジ日時 | 2024-06-29 00:15:30 | 
| 合計ジャッジ時間 | 2,048 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 | 
ソースコード
#include <bits/stdc++.h>
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
int main() {
  // ios_base::sync_with_stdio(false);
  string S;
  vector<int> cnt(26, 0);
  cin >> S;
  int n = S.size();
  rep(i, n) {
    cnt[S[i]- 'A']++;
  }
  const int mod = 573;
  
  vector<vector<ll>> nCk(n + 1, vector<ll>(n + 1, 0));
  nCk[0][0] = 1;
  rep(i, n) REP(j, 0, i + 1) {
    nCk[i + 1][j] += nCk[i][j];
    nCk[i + 1][j] %= mod;
    nCk[i + 1][j + 1] += nCk[i][j];
    nCk[i + 1][j + 1] %= mod;
  }
  ll ans = 1;
  rep(i, 26) {
    if(cnt[i]) {
      ans *= nCk[n][cnt[i]];
      ans %= mod;
      n -= cnt[i];
    }
  }
  ll tmp = 1;
  rep(i, n) {
    tmp *= cnt[S[i] - 'A'];
    tmp %= mod;
  }
  ans -= tmp;
  while(ans < 0) ans += mod;
  cout << ans << endl;
  
  return 0;
}
            
            
            
        