結果
問題 | No.170 スワップ文字列(Easy) |
ユーザー |
![]() |
提出日時 | 2020-06-05 16:08:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 789 bytes |
コンパイル時間 | 1,699 ms |
コンパイル使用メモリ | 173,840 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-12-16 01:07:11 |
合計ジャッジ時間 | 2,816 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int mod = 1e9; int memo[1010][1010]; int C(int n, int k) { if (memo[n][k] != -1) return memo[n][k]; if (n == 0) { return 1; } int ret = 0; if (k > 0) ret += C(n - 1, k - 1); if (k < n) ret += C(n - 1, k); return memo[n][k] = ret % mod; } int main() { string S; cin >> S; map<char, int> mp; for (auto& c : S) { mp[c]++; } for (int i = 0; i < 1001; i++) { for (int j = 0; j < 1001; j++) { memo[i][j] = -1; } } int ans = 1; int res = S.size(); for (auto& p : mp) { (ans *= C(res, p.second)) %= mod; res -= p.second; } ((ans += mod) -= 1) %= mod; cout << ans << endl; }