結果

問題 No.1967 Sugoroku Optimization
ユーザー simansiman
提出日時 2022-06-10 08:16:36
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 1,059 bytes
コンパイル時間 1,687 ms
コンパイル使用メモリ 131,164 KB
実行使用メモリ 34,992 KB
最終ジャッジ日時 2023-10-21 04:37:00
合計ジャッジ時間 4,792 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
34,992 KB
testcase_01 AC 10 ms
34,992 KB
testcase_02 AC 10 ms
34,992 KB
testcase_03 AC 298 ms
34,992 KB
testcase_04 AC 10 ms
34,992 KB
testcase_05 AC 294 ms
34,992 KB
testcase_06 AC 295 ms
34,992 KB
testcase_07 AC 11 ms
34,992 KB
testcase_08 AC 245 ms
34,992 KB
testcase_09 AC 225 ms
34,992 KB
testcase_10 AC 101 ms
34,992 KB
testcase_11 AC 27 ms
34,992 KB
testcase_12 AC 253 ms
34,992 KB
testcase_13 AC 154 ms
34,992 KB
testcase_14 AC 19 ms
34,992 KB
testcase_15 AC 20 ms
34,992 KB
testcase_16 AC 26 ms
34,992 KB
testcase_17 AC 29 ms
34,992 KB
testcase_18 AC 10 ms
34,992 KB
testcase_19 AC 10 ms
34,992 KB
testcase_20 AC 298 ms
34,992 KB
testcase_21 AC 10 ms
34,992 KB
testcase_22 AC 298 ms
34,992 KB
testcase_23 AC 253 ms
34,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll mod_pow(ll x, ll n, ll mod = MOD) {
  ll res = 1;

  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }

    x = x * x % mod;
    n >>= 1;
  }

  return res;
}

ll mod_inverse(ll x, ll mod = MOD) {
  return mod_pow(x, mod - 2, mod);
}

ll dp[2010][2010];

int main() {
  int N, K;
  cin >> N >> K;

  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;

  for (int i = 1; i <= K; ++i) {
    int remain = K - i + 1;
    ll sum = 0;

    for (int j = i; j <= N; ++j) {
      ll r = N - j + 1;

      if (j == N) {
        sum += dp[i - 1][j];
      }
      if (j - remain >= N) {
        sum += dp[i - 1][j - 1];
      } else {
        sum += dp[i - 1][j - 1] * mod_inverse(r);
      }

      sum %= MOD;
      dp[i][j] = sum;
    }
  }

  cout << dp[K][N] << endl;

  return 0;
}
0