結果
| 問題 |
No.2636 No Waiting in Vain
|
| ユーザー |
👑 |
| 提出日時 | 2024-02-18 13:35:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 544 bytes |
| コンパイル時間 | 287 ms |
| コンパイル使用メモリ | 82,360 KB |
| 実行使用メモリ | 133,652 KB |
| 最終ジャッジ日時 | 2024-09-29 00:23:53 |
| 合計ジャッジ時間 | 10,084 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 43 RE * 1 |
ソースコード
MOD = 998244353
N, K = map(int, input().split())
S = ['P'] + list(input())
if K > S.count('N'):
print(0)
exit()
facts = [1]
inv_facts = [1]
for i in range(1, N):
facts.append(facts[i-1] * i % MOD)
inv_facts.append(inv_facts[i-1] * pow(i, MOD-2, MOD) % MOD)
def comb(n, r):
return facts[n] * inv_facts[n-r] * inv_facts[r] % MOD
max_plan = S.count('N') - K
cnt = 0
for i in range(1, N+1):
if S[i] == 'N' and S[i-1] != 'C':
cnt += 1
print(sum(comb(cnt, i) for i in range(1, min(max_plan, cnt) + 1)) % MOD)