結果
問題 |
No.1967 Sugoroku Optimization
|
ユーザー |
![]() |
提出日時 | 2022-06-06 18:36:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 1,623 bytes |
コンパイル時間 | 352 ms |
コンパイル使用メモリ | 44,144 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-21 04:42:47 |
合計ジャッジ時間 | 1,244 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
/* -*- coding: utf-8 -*- * * 1967.cc: No.1967 Sugoroku Optimization - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 2000; const int MOD = 998244353; /* typedef */ template<const int MOD> struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) {} MI(long long _v): v(_v % MOD) {} 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); } 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); } }; typedef MI<MOD> mi; /* global variables */ mi invs[MAX_N + 1]; mi dp[2][MAX_N + 1]; /* subroutines */ /* main */ int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) invs[i] = mi(i).inv(); dp[0][0] = 1; int cur = 0, nxt = 1; while (k--) { fill(dp[nxt], dp[nxt] + n + 1, 0); for (int i = 0; i < n; i++) dp[nxt][i + 1] += dp[cur][i] * invs[n - i]; dp[nxt][n] += dp[cur][n]; for (int i = 0; i < n; i++) dp[nxt][i + 1] += dp[nxt][i]; swap(cur, nxt); } printf("%d\n", dp[cur][n].v); return 0; }