結果
問題 |
No.2530 Yellow Cards
|
ユーザー |
![]() |
提出日時 | 2023-11-03 22:36:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 190 ms / 2,000 ms |
コード長 | 2,133 bytes |
コンパイル時間 | 956 ms |
コンパイル使用メモリ | 111,020 KB |
最終ジャッジ日時 | 2025-02-17 18:36:31 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
ソースコード
// #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; }