結果
| 問題 | 
                            No.2636 No Waiting in Vain
                             | 
                    
| ユーザー | 
                            👑  | 
                    
| 提出日時 | 2024-02-18 13:51:09 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                            (最新)
                                AC
                                 
                             
                            (最初)
                            
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 530 bytes | 
| コンパイル時間 | 88 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 15,732 KB | 
| 最終ジャッジ日時 | 2024-09-29 00:24:27 | 
| 合計ジャッジ時間 | 3,443 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 24 RE * 20 | 
ソースコード
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)