結果

問題 No.2636 No Waiting in Vain
ユーザー loop0919loop0919
提出日時 2024-02-18 13:36:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 534 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 133,036 KB
最終ジャッジ日時 2024-02-18 13:36:59
合計ジャッジ時間 9,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,460 KB
testcase_01 AC 33 ms
53,460 KB
testcase_02 AC 32 ms
53,460 KB
testcase_03 AC 32 ms
53,460 KB
testcase_04 AC 372 ms
133,036 KB
testcase_05 AC 346 ms
133,036 KB
testcase_06 AC 347 ms
133,036 KB
testcase_07 AC 348 ms
133,036 KB
testcase_08 AC 363 ms
133,036 KB
testcase_09 AC 346 ms
133,036 KB
testcase_10 AC 343 ms
133,036 KB
testcase_11 AC 366 ms
133,036 KB
testcase_12 AC 338 ms
133,036 KB
testcase_13 AC 372 ms
133,036 KB
testcase_14 AC 371 ms
133,036 KB
testcase_15 AC 350 ms
133,036 KB
testcase_16 AC 341 ms
133,036 KB
testcase_17 AC 353 ms
133,036 KB
testcase_18 AC 363 ms
133,036 KB
testcase_19 AC 348 ms
133,036 KB
testcase_20 AC 340 ms
133,036 KB
testcase_21 AC 373 ms
133,036 KB
testcase_22 AC 342 ms
133,036 KB
testcase_23 AC 343 ms
133,036 KB
testcase_24 AC 43 ms
61,968 KB
testcase_25 AC 42 ms
61,968 KB
testcase_26 AC 44 ms
61,968 KB
testcase_27 AC 43 ms
61,968 KB
testcase_28 AC 44 ms
61,968 KB
testcase_29 AC 41 ms
61,968 KB
testcase_30 AC 46 ms
61,968 KB
testcase_31 AC 44 ms
61,968 KB
testcase_32 AC 42 ms
61,968 KB
testcase_33 AC 42 ms
61,968 KB
testcase_34 AC 43 ms
61,968 KB
testcase_35 AC 43 ms
61,968 KB
testcase_36 AC 43 ms
61,968 KB
testcase_37 AC 42 ms
61,968 KB
testcase_38 AC 42 ms
61,968 KB
testcase_39 AC 42 ms
61,968 KB
testcase_40 AC 42 ms
61,968 KB
testcase_41 AC 44 ms
61,968 KB
testcase_42 AC 42 ms
61,968 KB
testcase_43 AC 45 ms
61,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

N, K = map(int, input().split())
S = ['P'] + list(input())

# 階乗全列挙
facts = [1]
inv_facts = [1]

for i in range(1, N+1):
    facts.append(facts[i-1] * i % MOD)
    inv_facts.append(inv_facts[i-1] * pow(i, MOD-2, MOD) % MOD)

# nCr 全列挙
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)
0