結果

問題 No.2636 No Waiting in Vain
ユーザー loop0919loop0919
提出日時 2024-02-18 13:50:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 489 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 14,764 KB
最終ジャッジ日時 2024-02-18 13:50:30
合計ジャッジ時間 4,244 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
9,984 KB
testcase_01 AC 26 ms
9,984 KB
testcase_02 AC 25 ms
9,984 KB
testcase_03 AC 34 ms
9,984 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 27 ms
10,112 KB
testcase_25 AC 27 ms
10,240 KB
testcase_26 AC 26 ms
10,240 KB
testcase_27 AC 26 ms
10,240 KB
testcase_28 AC 26 ms
10,240 KB
testcase_29 AC 27 ms
10,240 KB
testcase_30 AC 27 ms
10,240 KB
testcase_31 AC 28 ms
10,240 KB
testcase_32 AC 26 ms
10,240 KB
testcase_33 AC 27 ms
10,240 KB
testcase_34 AC 27 ms
10,240 KB
testcase_35 AC 27 ms
10,240 KB
testcase_36 AC 27 ms
10,240 KB
testcase_37 AC 28 ms
10,240 KB
testcase_38 AC 28 ms
10,240 KB
testcase_39 AC 26 ms
10,240 KB
testcase_40 AC 27 ms
10,240 KB
testcase_41 AC 36 ms
10,240 KB
testcase_42 AC 29 ms
10,240 KB
testcase_43 AC 29 ms
10,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import cache
MOD = 998244353

N, K = map(int, input().split())
S = ['P'] + list(input())

@cache
def fact(n):
    if n == 0:
        return 1
    return fact(n-1) * n % MOD

@cache
def inv_fact(n):
    return pow(fact(n), -1, MOD)

def comb(n, r):
    return fact(n) * inv_fact(n-r) * inv_fact(r) % MOD

max_plan = S.count('N') - K
cnt = sum(1 for i in range(1, N+1) if S[i] == 'N' and S[i-1] != 'C')
print(sum(comb(cnt, i) for i in range(1, min(max_plan, cnt) + 1)) % MOD)
0