結果

問題 No.170 スワップ文字列(Easy)
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-02-27 23:34:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,040 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 90,436 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 17:07:30
合計ジャッジ時間 1,589 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;

const int MOD = 1000000007; // 10^9 + 7

int comb(int n, int r) {
  if (n < r)  return 0;
  if (n == r) return 1;
  if (r == 0) return 1;
  return comb(n - 1, r - 1) + comb(n - 1, r);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s; cin >> s;
  int n = s.size();
  map<char, int> mm;

  for (int i = 0; i < n; i++) {
    if (mm.count(s[i]) == 0) {
      mm.insert(make_pair(s[i], 1));
    } else {
      mm[s[i]]++;
    }
  }

  int ans = 1;
  auto begin = mm.begin(), end = mm.end();

  for (auto iter = begin; iter != end; iter++) {
    ans *= comb(n, iter->second);
    n -= iter->second;
  }

  cout << ans - 1 << endl;
}
0