結果

問題 No.1889 K Consecutive Ks (Hard)
ユーザー miscalcmiscalc
提出日時 2021-10-03 13:51:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 863 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 200,868 KB
実行使用メモリ 13,476 KB
最終ジャッジ日時 2024-04-15 00:49:07
合計ジャッジ時間 9,587 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;

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

  vector<int> D(N + 10, 0);
  for (int i = 2; i <= M; i++)
  {
    for (int k = 1; k * i <= N; k++)
    {
      D[k * i - 1]++;
    }
  }

  vector<mint> pw(N + 10);
  pw[0] = 0, pw[1] = 1, pw[2] = M - 2;
  for (int i = 2; i < N; i++)
  {
    pw[i + 1] = (M - 1) * pw[i];
  }

  vector<mint> dp(N + 10, 0);
  vector<mint> dp2(N + 10);
  dp2[0] = 1;
  for (int i = 0; i < N; i++)
  {
    dp2[i + 1] = (M - 1) * dp2[i];
  }

  for (int i = 0; i <= N; i++)
  {
    for (int j = 0; j < i; j++)
    {
      dp[i] += dp2[j] * D[i - j];
    }

    for (int j = 0; j < i; j++)
    {
      dp2[i] -= dp[j] * pw[i - j];
    }
  }

  mint ans = ((mint)M).pow(N) - dp2[N];
  cout << ans.val() << endl;
}
0