結果

問題 No.2636 No Waiting in Vain
ユーザー rlangevinrlangevin
提出日時 2024-02-18 13:09:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 731 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 97,612 KB
最終ジャッジ日時 2024-02-18 13:09:21
合計ジャッジ時間 5,104 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
67,396 KB
testcase_01 AC 48 ms
67,396 KB
testcase_02 AC 47 ms
67,396 KB
testcase_03 AC 51 ms
67,396 KB
testcase_04 AC 87 ms
97,612 KB
testcase_05 AC 98 ms
97,612 KB
testcase_06 AC 85 ms
97,608 KB
testcase_07 AC 88 ms
97,612 KB
testcase_08 AC 83 ms
97,608 KB
testcase_09 AC 88 ms
97,612 KB
testcase_10 AC 93 ms
97,612 KB
testcase_11 AC 82 ms
97,604 KB
testcase_12 AC 93 ms
97,612 KB
testcase_13 AC 87 ms
97,612 KB
testcase_14 AC 85 ms
97,612 KB
testcase_15 AC 90 ms
97,604 KB
testcase_16 AC 81 ms
97,612 KB
testcase_17 AC 92 ms
97,608 KB
testcase_18 AC 83 ms
97,612 KB
testcase_19 AC 92 ms
97,612 KB
testcase_20 AC 90 ms
97,612 KB
testcase_21 AC 90 ms
97,612 KB
testcase_22 AC 86 ms
97,612 KB
testcase_23 AC 95 ms
97,612 KB
testcase_24 AC 49 ms
69,756 KB
testcase_25 AC 50 ms
69,756 KB
testcase_26 AC 50 ms
69,756 KB
testcase_27 AC 52 ms
69,756 KB
testcase_28 AC 51 ms
69,756 KB
testcase_29 AC 50 ms
69,760 KB
testcase_30 AC 50 ms
69,756 KB
testcase_31 AC 52 ms
69,756 KB
testcase_32 AC 50 ms
69,760 KB
testcase_33 AC 51 ms
69,760 KB
testcase_34 AC 77 ms
69,760 KB
testcase_35 AC 51 ms
69,756 KB
testcase_36 AC 51 ms
69,756 KB
testcase_37 AC 48 ms
67,620 KB
testcase_38 AC 49 ms
69,756 KB
testcase_39 AC 48 ms
69,756 KB
testcase_40 AC 53 ms
69,756 KB
testcase_41 AC 59 ms
69,756 KB
testcase_42 AC 53 ms
69,760 KB
testcase_43 AC 54 ms
69,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
S = list(input())
mod = 998244353
n = 505050
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod

cnt = 0
flag = 0
for s in S:
    if s == "C":
        flag = 1
    elif s == "N":
        if not flag:
            cnt += 1
        else:
            K -= 1
        flag = 0
    else:
        flag = 0
        
ans = 0
for i in range(1, cnt - K + 1):
    ans += comb(cnt, i)
    ans %= mod
print(ans)
0