結果

問題 No.2530 Yellow Cards
ユーザー GOTKAKOGOTKAKO
提出日時 2023-11-03 23:05:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 2,295 ms
コンパイル使用メモリ 207,076 KB
実行使用メモリ 198,832 KB
最終ジャッジ日時 2023-11-03 23:05:44
合計ジャッジ時間 7,159 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 396 ms
198,832 KB
testcase_08 AC 395 ms
198,832 KB
testcase_09 AC 400 ms
198,832 KB
testcase_10 AC 395 ms
198,568 KB
testcase_11 AC 394 ms
198,304 KB
testcase_12 AC 400 ms
198,568 KB
testcase_13 AC 393 ms
198,304 KB
testcase_14 AC 315 ms
139,960 KB
testcase_15 AC 215 ms
90,328 KB
testcase_16 AC 192 ms
92,440 KB
testcase_17 AC 327 ms
152,368 KB
testcase_18 AC 96 ms
61,024 KB
testcase_19 AC 22 ms
16,936 KB
testcase_20 AC 58 ms
23,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long mod = 998244353;
long long power(long long a, long long b){
    long long p = a, ret = 1;
    for(int i=0; i<30; i++){
        if(b&(1<<i)) ret = ret*p %mod;
        p = p*p %mod;
    }
    return ret;
}

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

    int N,K; cin >> N >> K;
    long long perN = power(N,mod-2);
    vector<vector<long long>> dp(K+1,vector<long long>(N+1));
    dp.at(0).at(0) = 1;
    for(int i=0; i<K; i++){
        for(int k=0; k<=N; k++){
            if(dp.at(i).at(k) == 0) continue;
            long long red = k*perN%mod;
            if(k) dp.at(i+1).at(k-1) = (dp.at(i+1).at(k-1)+dp.at(i).at(k)*red)%mod;
            if(k != N) dp.at(i+1).at(k+1) = (dp.at(i+1).at(k+1)+dp.at(i).at(k)*(mod+1-red))%mod;
        }
    }

    long long answer = 0;
    for(int i=0; i<=N; i++){
        if(dp.at(K).at(i) == 0) continue;
        long long out = (K-i)/2;
        answer = (answer+dp.at(K).at(i)*(out+N))%mod;
    }
    cout << answer << endl;
}
0