結果

問題 No.2530 Yellow Cards
ユーザー ococonomy1ococonomy1
提出日時 2023-11-03 22:36:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 2,133 bytes
コンパイル時間 1,219 ms
コンパイル使用メモリ 114,148 KB
実行使用メモリ 198,844 KB
最終ジャッジ日時 2023-11-03 22:36:08
合計ジャッジ時間 4,316 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 173 ms
198,844 KB
testcase_03 AC 28 ms
35,428 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 170 ms
198,844 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 218 ms
198,844 KB
testcase_08 AC 214 ms
198,844 KB
testcase_09 AC 192 ms
198,844 KB
testcase_10 AC 194 ms
198,580 KB
testcase_11 AC 193 ms
198,580 KB
testcase_12 AC 194 ms
198,844 KB
testcase_13 AC 192 ms
198,316 KB
testcase_14 AC 181 ms
188,020 KB
testcase_15 AC 166 ms
152,116 KB
testcase_16 AC 98 ms
100,636 KB
testcase_17 AC 174 ms
182,212 KB
testcase_18 AC 36 ms
39,652 KB
testcase_19 AC 7 ms
9,556 KB
testcase_20 AC 87 ms
101,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
// #define AMARI 1000000007
#define TIME_LIMIT 1980000
#define el '\n'
#define El '\n'

ll bekizyou(ll a,ll b){
    ll temp = a,ans = 1;
    while(b){
        if(b % 2){
            ans *= temp;
            ans %= AMARI;
        }
        temp *= temp;
        b /= 2;
        temp %= AMARI;
    }
    return ans;
}

ll gyakugen(ll a){
    return bekizyou(a,AMARI - 2);
}

#define MULTI_TEST_CASE false
void solve(void) {
    int n,k;
    cin >> n >> k;
    //dp[i][j] := i番目のイベントが終わった直後について、イエローカードを1回つきつけられた人がj人いる確率
    vector<vector<ll>> dp(k + 1,vector<ll>(k + 1,0));
    dp[0][0] = 1;
    ll gn = gyakugen(n);
    for(int i = 0; i < k; i++){
        for(int j = 0; j <= k; j++){
            if(dp[i][j] == 0)continue;
            if(j != k){
                dp[i + 1][j + 1] += dp[i][j] * ((n - j) * gn % AMARI);
                dp[i + 1][j + 1] %= AMARI;
            }
            if(j != 0){
                dp[i + 1][j - 1] += dp[i][j] * (j * gn % AMARI);
                dp[i + 1][j - 1] %= AMARI;
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i <= k; i++){
        //dp[k][i]ということは、2回つきつけられた人が(k-i)/2人いることになる
        ans += dp[k][i] * (n + (k - i) / 2);
        ans %= AMARI;
    }
    cout << ans << el;
    return;
}

void calc(void) {
    return;
}

signed main(void) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE) cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
0