結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
9,984 KB
testcase_01 AC 25 ms
9,984 KB
testcase_02 AC 25 ms
9,984 KB
testcase_03 AC 25 ms
9,984 KB
testcase_04 AC 281 ms
65,480 KB
testcase_05 AC 310 ms
65,508 KB
testcase_06 AC 261 ms
65,324 KB
testcase_07 AC 287 ms
66,124 KB
testcase_08 AC 205 ms
63,008 KB
testcase_09 AC 292 ms
65,760 KB
testcase_10 AC 298 ms
65,948 KB
testcase_11 AC 161 ms
62,876 KB
testcase_12 AC 282 ms
65,664 KB
testcase_13 AC 284 ms
65,700 KB
testcase_14 AC 267 ms
64,708 KB
testcase_15 AC 288 ms
65,676 KB
testcase_16 AC 148 ms
63,144 KB
testcase_17 AC 280 ms
65,936 KB
testcase_18 AC 245 ms
65,020 KB
testcase_19 AC 303 ms
65,748 KB
testcase_20 AC 287 ms
65,664 KB
testcase_21 AC 291 ms
65,740 KB
testcase_22 AC 269 ms
65,584 KB
testcase_23 AC 304 ms
65,548 KB
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 27 ms
10,240 KB
testcase_28 AC 27 ms
10,240 KB
testcase_29 AC 26 ms
10,240 KB
testcase_30 AC 26 ms
10,240 KB
testcase_31 AC 27 ms
10,240 KB
testcase_32 AC 27 ms
10,240 KB
testcase_33 AC 26 ms
10,240 KB
testcase_34 AC 27 ms
10,240 KB
testcase_35 AC 26 ms
10,240 KB
testcase_36 AC 28 ms
10,240 KB
testcase_37 AC 27 ms
10,240 KB
testcase_38 AC 27 ms
10,240 KB
testcase_39 AC 27 ms
10,240 KB
testcase_40 AC 26 ms
10,240 KB
testcase_41 AC 25 ms
10,240 KB
testcase_42 AC 26 ms
10,240 KB
testcase_43 AC 28 ms
10,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

MOD = 998244353

@cache
def fact(n):
    return 1 if n == 0 else 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

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

max_plan = S.count('N') - K
cnt = len(list(filter(lambda i: S[i] == 'N' and S[i-1] != 'C', range(1, N+1))))
ans = sum(comb(cnt, i) for i in range(1, min(max_plan, cnt) + 1)) % MOD

print(ans)
0