結果

問題 No.2636 No Waiting in Vain
ユーザー elphe
提出日時 2024-08-11 14:52:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 69,212 KB
最終ジャッジ日時 2025-02-23 22:25:01
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdint>

#define MOD   998244353

using namespace std;

constexpr unsigned int pow_mod(const unsigned long long a, const unsigned long long b, const unsigned int mod)
{
	return (b == 0 ? (mod == 1 ? 0 : 1) : (b & 1 ? a % mod : 1) * pow_mod((a % mod) * (a % mod) % mod, b >> 1, mod) % mod);
}

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	uint32_t N, K, i, count = 0, ans = 0, temp;
	cin >> N >> K;
	string S;
	S.reserve(N), cin >> S;

	if (S[0] == 'N') ++count;
	for (i = 1; i != N; ++i)
		if (S[i] == 'N')
		{
			if (S[i - 1] == 'C')
			{
				if (K != 0) --K;
			}
			else ++count;
		}

	if (count < K) cout << "0\n";
	else
	{
		temp = count;
		for (i = 1; i <= count - K; ++i)
			ans = (ans + temp) % MOD, temp = temp * static_cast<uint64_t>(count - i) % MOD * pow_mod(i + 1, MOD - 2, MOD) % MOD;
		cout << ans << '\n';
	}

	return 0;
}
0