結果
| 問題 |
No.171 スワップ文字列(Med)
|
| コンテスト | |
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2019-09-28 15:26:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 1,000 ms |
| コード長 | 2,081 bytes |
| コンパイル時間 | 1,474 ms |
| コンパイル使用メモリ | 165,964 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-10-02 08:30:28 |
| 合計ジャッジ時間 | 2,086 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;
template<int mod>
struct mint {
private:
ll x;
public:
mint(ll x = 0) :x(x%mod) {}
mint(string s) {
ll z = 0;
REP(i, s.size()) {
z *= 10;
z += s[i] - '0';
z %= mod;
}
this->x = z;
}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod - a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
friend ostream& operator<<(ostream& os, const mint& n) {
return os << n.x;
}
bool operator==(const mint a) const {
return this->x == a.x;
}
};
int main() {
string s; cin >> s;
int n = s.size();
mint<573> ans = 1;
vector<vector<mint<573>>> comb(n + 1, vector<mint<573>>(n + 1, 0));
REP(i, n + 1) {
comb[i][0] = 1;
comb[i][i] = 1;
}
FOR(i, 1, n + 1) {
FOR(j, 1, i) {
comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
}
}
/*
REP(i, n + 1) {
REP(j, n + 1) {
cout << "comb[" << i << "][" << j << "] = " << comb[i][j] << endl;
}
}
*/
vector<int> cnt(26, 0);
REP(i, n) {
cnt[s[i] - 'A']++;
}
REP(i, 26) {
ans *= comb[n][cnt[i]];
n -= cnt[i];
}
cout << ans - 1<< endl;
return 0;
}
🍮かんプリン