結果
| 問題 |
No.171 スワップ文字列(Med)
|
| コンテスト | |
| ユーザー |
commy
|
| 提出日時 | 2019-03-31 00:40:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 1,000 ms |
| コード長 | 1,240 bytes |
| コンパイル時間 | 814 ms |
| コンパイル使用メモリ | 80,464 KB |
| 実行使用メモリ | 7,296 KB |
| 最終ジャッジ日時 | 2024-11-17 14:13:58 |
| 合計ジャッジ時間 | 1,545 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif
using namespace std;
typedef long long int ll;
template<typename T>
vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
const int mod = 573;
string s;
cin >> s;
int N = s.size();
auto mp = make_v(N + 1, N + 1, -1);
function<int(int, int)> nCr = [&](int n, int r) -> int {
if (mp[n][r] != -1) return mp[n][r];
if (n == r || r == 0) return 1;
return mp[n][r] = (nCr(n - 1, r - 1) + nCr(n - 1, r)) % mod;
};
vector<int> cnt(26, 0);
REP(i, 0, N) {
cnt[s[i] - 'A']++;
}
int ans = 1;
int rem = N;
REP(i, 0, 26) {
ans *= (nCr(rem, cnt[i]));
ans %= mod;
rem -= cnt[i];
}
ans = (ans + mod - 1) % mod;
cout << ans << endl;
return 0;
}
commy