結果
| 問題 |
No.2530 Yellow Cards
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-06-19 15:11:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 2,000 ms |
| コード長 | 1,936 bytes |
| コンパイル時間 | 503 ms |
| コンパイル使用メモリ | 43,392 KB |
| 最終ジャッジ日時 | 2025-02-21 23:18:47 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:66:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
66 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2530.cc: No.2530 Yellow Cards - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 5000;
const int MAX_K = 5000;
const int MOD = 998244353;
/* typedef */
template<const int MOD>
struct MI {
int v;
MI(): v() {}
MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }
MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }
explicit operator int() const { return v; }
MI operator+(const MI m) const { return MI(v + m.v); }
MI operator-(const MI m) const { return MI(v + MOD - m.v); }
MI operator*(const MI m) const { return MI((long long)v * m.v); }
MI &operator+=(const MI m) { return (*this = *this + m); }
MI &operator-=(const MI m) { return (*this = *this - m); }
MI &operator*=(const MI m) { return (*this = *this * m); }
bool operator==(const MI m) const { return v == m.v; }
bool operator!=(const MI m) const { return v != m.v; }
MI pow(int n) const { // a^n % MOD
MI pm = 1, a = *this;
while (n > 0) {
if (n & 1) pm *= a;
a *= a;
n >>= 1;
}
return pm;
}
MI inv() const { return pow(MOD - 2); }
MI operator/(const MI m) const { return *this * m.inv(); }
MI &operator/=(const MI m) { return (*this = *this / m); }
};
using mi = MI<MOD>;
/* global variables */
mi dp[2][MAX_N + 1];
/* subroutines */
/* main */
int main() {
int n, k;
scanf("%d%d", &n, &k);
dp[0][0] = 1;
mi invn = mi(n).inv();
int cur = 0, nxt = 1;
for (int i = 0; i < k; i++) {
fill(dp[nxt], dp[nxt] + n + 1, 0);
for (int j = 0; j <= n; j++)
if (dp[cur][j] != 0) {
if (j > 0)
dp[nxt][j - 1] += dp[cur][j] * j * invn;
if (j < n)
dp[nxt][j + 1] += dp[cur][j] * (n - j) * invn;
}
swap(cur, nxt);
}
mi e = n;
int maxj = min(n, k);
for (int j = 0; j <= maxj; j++)
e += dp[cur][j] * ((k - j) / 2);
printf("%d\n", (int)e);
return 0;
}
tnakao0123