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