結果
問題 | No.1927 AB-CD |
ユーザー |
![]() |
提出日時 | 2022-05-06 22:04:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 1,199 bytes |
コンパイル時間 | 1,587 ms |
コンパイル使用メモリ | 169,804 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-05 23:18:15 |
合計ジャッジ時間 | 2,682 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n); i >= 0; i--) #define all(v) v.begin(), v.end() #define mod1 1000000007 #define mod2 998244353 typedef long long ll; ll my_pow(ll x, ll n, ll mod){ // 繰り返し二乗法.x^nをmodで割った余り. ll ret; if (n == 0){ ret = 1; } else if (n % 2 == 1){ ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod; } else{ ret = my_pow((x * x) % mod, n / 2, mod); } return ret; } int main(){ int N; cin >> N; string S; cin >> S; ll ab = 0; ll cd = 0; vector<ll> factorial(300005, 0); factorial[0] = 1; for (ll i = 0; i < 300004; i++){ factorial[i + 1] = (factorial[i] * (i + 1)) % mod2; } for (int i = 0; i < N; i++){ if (S[i] == 'A' || S[i] == 'B'){ ab++; } else{ cd++; } } ll ans = 1; ans = (ans * factorial[N]) % mod2; ans = (ans * my_pow(factorial[ab], mod2 - 2, mod2)) % mod2; ans = (ans * my_pow(factorial[cd], mod2 - 2, mod2)) % mod2; cout << ans << endl; }