結果

問題 No.1889 K Consecutive Ks (Hard)
ユーザー miscalcmiscalc
提出日時 2021-10-07 15:54:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 810 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 202,484 KB
実行使用メモリ 813,952 KB
最終ジャッジ日時 2024-04-15 00:49:37
合計ジャッジ時間 3,974 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 MLE -
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<vector<mint>> dp(N + 1, vector<mint>(M + 1, 0));
  for (int i = 0; i <= N; i++)
  {
    dp.at(i).at(1) = 1;
  }
  for (int j = 1; j <= M; j++)
  {
    dp.at(0).at(j) = 1;
  }
  for (int i = 1; i <= N; i++)
  {
    for (int j = 2; j <= M; j++)
    {
      dp.at(i).at(j) += dp.at(i).at(j - 1);
      dp.at(i).at(j) += dp.at(i - 1).at(M);
      if (i - j >= 0)
      {
        dp.at(i).at(j) -= dp.at(i - j).at(j - 1);
        dp.at(i).at(j) += dp.at(i - j).at(j);
        dp.at(i).at(j) -= dp.at(i - j).at(M);
      }
    }
  }

  mint ans = ((mint)M).pow(N) - (dp.at(N).at(M) - dp.at(N - 1).at(M));
  cout << ans.val() << endl;
}
0