結果

問題 No.2636 No Waiting in Vain
ユーザー loop0919loop0919
提出日時 2024-02-18 13:51:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 530 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 66,100 KB
最終ジャッジ日時 2024-02-18 13:51:18
合計ジャッジ時間 7,492 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
9,984 KB
testcase_01 AC 25 ms
9,984 KB
testcase_02 AC 26 ms
9,984 KB
testcase_03 AC 26 ms
9,984 KB
testcase_04 AC 293 ms
65,456 KB
testcase_05 AC 289 ms
65,484 KB
testcase_06 AC 248 ms
65,300 KB
testcase_07 AC 272 ms
66,100 KB
testcase_08 AC 193 ms
62,496 KB
testcase_09 AC 292 ms
65,736 KB
testcase_10 AC 274 ms
65,924 KB
testcase_11 AC 148 ms
62,356 KB
testcase_12 AC 266 ms
65,640 KB
testcase_13 AC 268 ms
65,676 KB
testcase_14 AC 251 ms
64,684 KB
testcase_15 AC 268 ms
65,652 KB
testcase_16 AC 132 ms
62,500 KB
testcase_17 AC 276 ms
65,912 KB
testcase_18 AC 233 ms
64,996 KB
testcase_19 AC 293 ms
65,724 KB
testcase_20 AC 279 ms
65,640 KB
testcase_21 AC 269 ms
65,716 KB
testcase_22 AC 257 ms
65,560 KB
testcase_23 AC 271 ms
65,524 KB
testcase_24 AC 34 ms
10,240 KB
testcase_25 AC 26 ms
10,240 KB
testcase_26 AC 26 ms
10,240 KB
testcase_27 AC 28 ms
10,240 KB
testcase_28 AC 28 ms
10,240 KB
testcase_29 AC 29 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 28 ms
10,240 KB
testcase_35 AC 27 ms
10,240 KB
testcase_36 AC 26 ms
10,240 KB
testcase_37 AC 28 ms
10,240 KB
testcase_38 AC 27 ms
10,240 KB
testcase_39 AC 27 ms
10,240 KB
testcase_40 AC 27 ms
10,240 KB
testcase_41 AC 26 ms
10,240 KB
testcase_42 AC 26 ms
10,240 KB
testcase_43 AC 26 ms
10,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import cache
import sys
sys.setrecursionlimit(10**6)

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