結果
| 問題 |
No.171 スワップ文字列(Med)
|
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2025-02-19 00:44:09 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 1,000 ms |
| コード長 | 1,364 bytes |
| コンパイル時間 | 3,454 ms |
| コンパイル使用メモリ | 287,812 KB |
| 実行使用メモリ | 7,808 KB |
| 最終ジャッジ日時 | 2025-02-19 00:44:14 |
| 合計ジャッジ時間 | 4,385 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "settings/debug.cpp"
#else
#define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
constexpr int MOD = 573;
class Integer {
map<int, int> factors;
public:
Integer() = default;
Integer(int n) {
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
factors[i]++;
n /= i;
}
}
if (n > 1) factors[n]++;
}
int out() const {
int res = 1;
for (auto [p, e] : factors) {
rep(_, e) res = res * p % MOD;
}
return res;
}
Integer operator*(const Integer& rhs) const {
Integer res;
for (auto [p, e] : factors) res.factors[p] += e;
for (auto [p, e] : rhs.factors) res.factors[p] += e;
return res;
}
Integer operator/(const Integer& rhs) const {
Integer res;
for (auto [p, e] : factors) res.factors[p] += e;
for (auto [p, e] : rhs.factors) res.factors[p] -= e;
return res;
}
};
int main() {
string s;
cin >> s;
vector<Integer> fact(s.size() + 1);
rep(i, s.size()) fact[i + 1] = Integer(i + 1) * fact[i];
vector<int> cnt(26, 0);
for (char c : s) cnt[c - 'A']++;
Integer res = fact[s.size()];
for (int c : cnt) res = res / fact[c];
cout << (res.out() - 1 + MOD) % MOD << '\n';
return 0;
}
a01sa01to