結果

問題 No.2530 Yellow Cards
ユーザー keisuke6keisuke6
提出日時 2023-11-03 22:30:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,841 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 205,572 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 22:30:50
合計ジャッジ時間 21,045 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1,820 ms
4,348 KB
testcase_08 AC 1,807 ms
4,348 KB
testcase_09 AC 1,815 ms
4,348 KB
testcase_10 AC 1,828 ms
4,348 KB
testcase_11 AC 1,816 ms
4,348 KB
testcase_12 AC 1,841 ms
4,348 KB
testcase_13 AC 1,814 ms
4,348 KB
testcase_14 AC 1,276 ms
4,348 KB
testcase_15 AC 793 ms
4,348 KB
testcase_16 AC 824 ms
4,348 KB
testcase_17 AC 1,328 ms
4,348 KB
testcase_18 AC 527 ms
4,348 KB
testcase_19 AC 127 ms
4,348 KB
testcase_20 AC 180 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 998244353;
long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}
signed main(){
	int N,K;
	cin>>N>>K;
	int k = modinv(N);
	vector<int> dp(N+1,0);
	dp[0] = 1;
	for(int i=0;i<K;i++){
		vector<int> ddp(N+1,0);
		for(int j=0;j<N;j++) ddp[j+1] = (ddp[j+1]+dp[j]*k%mod*(N-j)%mod)%mod;
		for(int j=N;j>0;j--) ddp[j-1] = (ddp[j-1]+dp[j]*k%mod*j%mod)%mod;
		dp = ddp;
	}
	int ans = 0;
	for(int i=0;i<=N;i++) ans = (ans+(N+(K-i)/2)*dp[i])%mod;
	cout<<ans<<endl;
}
0