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