結果

問題 No.1927 AB-CD
ユーザー ぷらぷら
提出日時 2022-05-06 21:25:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 198,684 KB
実行使用メモリ 36,716 KB
最終ジャッジ日時 2023-09-20 02:13:15
合計ジャッジ時間 5,838 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void COMinit()’ 内:
main.cpp:13:29: 警告: iteration 200004 invokes undefined behavior [-Waggressive-loop-optimizations]
   13 |         finv[i] = finv[i - 1] * inv[i] % mod;
      |                   ~~~~~~~~~~^
main.cpp:10:23: 備考: within this loop
   10 |     for (int i = 2; i < 2000005; i++) {
      |                     ~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long fac[2000005], finv[200005], inv[2000005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 2000005; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
    int N;
    string S;
    cin >> N >> S;
    COMinit();
    int a = 0,c = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] == 'A' || S[i] == 'B') {
            a++;
        }
        else {
            c++;
        }
    }
    cout << COM(N,a) << endl;
}
0