結果
問題 | No.170 スワップ文字列(Easy) |
ユーザー |
![]() |
提出日時 | 2019-03-03 15:21:03 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 620 bytes |
コンパイル時間 | 1,410 ms |
コンパイル使用メモリ | 166,312 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-23 13:13:30 |
合計ジャッジ時間 | 2,208 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { // 1. 入力情報取得. string S; cin >> S; // 2. S の 各文字 を 入れ替える. int l = S.size(); map<char, int> m; for(int i = 0; i < l; i++) m[S[i]]++; // 3. 組み合わせ数を計算. // ex. XYZYX なら 5! ÷ 2! ÷ 2! ÷ 1! = 30 と計算. int fac[8] = {1, 2, 6, 24, 120, 720, 5040, 40320}; int ans = fac[l - 1]; for(auto &p : m) ans /= fac[p.second - 1]; // ex. XYZYX なら 30 - 1 = 29 と計算. ans--; // 4. 出力. cout << ans << endl; return 0; }