結果
問題 |
No.170 スワップ文字列(Easy)
|
ユーザー |
![]() |
提出日時 | 2020-02-27 23:34:24 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,040 bytes |
コンパイル時間 | 670 ms |
コンパイル使用メモリ | 92,376 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 16:04:34 |
合計ジャッジ時間 | 1,371 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#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; }