結果

問題 No.2530 Yellow Cards
ユーザー shobonvipshobonvip
提出日時 2023-10-24 22:30:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 2,436 ms
コンパイル使用メモリ 208,388 KB
実行使用メモリ 101,296 KB
最終ジャッジ日時 2023-10-24 22:30:45
合計ジャッジ時間 6,656 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 353 ms
101,296 KB
testcase_08 AC 352 ms
101,296 KB
testcase_09 AC 356 ms
101,296 KB
testcase_10 AC 351 ms
101,296 KB
testcase_11 AC 377 ms
101,032 KB
testcase_12 AC 354 ms
101,032 KB
testcase_13 AC 378 ms
101,032 KB
testcase_14 AC 246 ms
71,728 KB
testcase_15 AC 158 ms
46,912 KB
testcase_16 AC 159 ms
47,968 KB
testcase_17 AC 272 ms
78,064 KB
testcase_18 AC 104 ms
32,128 KB
testcase_19 AC 26 ms
10,216 KB
testcase_20 AC 37 ms
13,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/modint>
typedef atcoder::modint998244353 mint;

int main(){
	int n, k; cin >> n >> k;
	mint ans = n;
	mint ninv = mint(n).inv();

	vector dp(k+1, vector<mint>(n+1));
	dp[0][0] = 1;

	for (int i=0; i<k; i++){
		for (int j=0; j<=n; j++){
			// select reach
			if (j > 0){
				dp[i+1][j-1] += mint(j) * ninv * dp[i][j];
				ans += mint(j) * ninv * dp[i][j];
			}
			// select other
			if (j < n){
				dp[i+1][j+1] += mint(n-j) * ninv * dp[i][j];
			}
		}
	}

	cout << ans.val() << '\n';
}
0