結果

問題 No.171 スワップ文字列(Med)
ユーザー purple_jwlpurple_jwl
提出日時 2015-03-22 23:47:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 1,054 bytes
コンパイル時間 1,303 ms
コンパイル使用メモリ 150,624 KB
実行使用メモリ 11,012 KB
最終ジャッジ日時 2023-09-11 09:36:56
合計ジャッジ時間 2,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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;
}
0