結果

問題 No.2636 No Waiting in Vain
ユーザー Nichi10pNichi10p
提出日時 2024-02-22 00:16:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 826 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 202,540 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-02-22 00:16:10
合計ジャッジ時間 4,458 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
7,168 KB
testcase_01 AC 7 ms
7,168 KB
testcase_02 AC 7 ms
7,168 KB
testcase_03 AC 7 ms
7,168 KB
testcase_04 AC 16 ms
7,296 KB
testcase_05 AC 16 ms
7,296 KB
testcase_06 AC 16 ms
7,296 KB
testcase_07 AC 16 ms
7,296 KB
testcase_08 AC 16 ms
7,296 KB
testcase_09 AC 16 ms
7,296 KB
testcase_10 AC 16 ms
7,296 KB
testcase_11 AC 15 ms
7,296 KB
testcase_12 AC 17 ms
7,296 KB
testcase_13 AC 16 ms
7,296 KB
testcase_14 AC 16 ms
7,296 KB
testcase_15 AC 16 ms
7,296 KB
testcase_16 AC 16 ms
7,296 KB
testcase_17 AC 16 ms
7,296 KB
testcase_18 AC 16 ms
7,296 KB
testcase_19 AC 16 ms
7,296 KB
testcase_20 AC 16 ms
7,296 KB
testcase_21 AC 16 ms
7,296 KB
testcase_22 AC 15 ms
7,296 KB
testcase_23 AC 16 ms
7,296 KB
testcase_24 AC 7 ms
7,168 KB
testcase_25 AC 7 ms
7,168 KB
testcase_26 AC 7 ms
7,168 KB
testcase_27 AC 7 ms
7,168 KB
testcase_28 AC 8 ms
7,168 KB
testcase_29 AC 8 ms
7,168 KB
testcase_30 AC 8 ms
7,168 KB
testcase_31 AC 8 ms
7,168 KB
testcase_32 AC 7 ms
7,168 KB
testcase_33 AC 7 ms
7,168 KB
testcase_34 AC 8 ms
7,168 KB
testcase_35 AC 16 ms
7,168 KB
testcase_36 AC 7 ms
7,168 KB
testcase_37 AC 7 ms
7,168 KB
testcase_38 AC 7 ms
7,168 KB
testcase_39 AC 7 ms
7,168 KB
testcase_40 AC 7 ms
7,168 KB
testcase_41 AC 7 ms
7,168 KB
testcase_42 AC 7 ms
7,168 KB
testcase_43 AC 8 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;

  constexpr int mod = 998244353;
  int fact[300001], inv[300001], inv_fact[300001];
  fact[0] = inv_fact[0] = 1;
  fact[1] = inv_fact[1] = inv[1] = 1;
  for (int i = 2; i <= 300000; ++i) {
    fact[i] = (long long)i * fact[i-1] % mod;
    inv[i] = (long long)(mod - inv[mod % i]) * (mod / i) % mod;
    inv_fact[i] = (long long)inv[i] * inv_fact[i-1] % mod;
  }

  int cnt{};
  for (int i = 0; i < N; ++i)
    if (S[i] == 'N') {
      if (i == 0)
        ++cnt;
      else if (S[i-1] == 'C')
        --K;
      else
        ++cnt;
    }
  int ans{};
  for (int k = 1; k <= cnt - max(K, 0); ++k) {
    ans += (long long)fact[cnt] * inv_fact[cnt-k] % mod * inv_fact[k] % mod;
    ans %= mod;
  }

  cout << ans << endl;
}
0