結果
| 問題 |
No.1887 K Consecutive Ks (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-25 22:06:37 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 117 ms / 2,000 ms |
| コード長 | 749 bytes |
| コンパイル時間 | 4,301 ms |
| コンパイル使用メモリ | 283,004 KB |
| 実行使用メモリ | 38,656 KB |
| 最終ジャッジ日時 | 2024-10-14 06:01:25 |
| 合計ジャッジ時間 | 5,835 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
#include <atcoder/convolution>
using namespace std;
using Mint = atcoder::modint998244353;
int main()
{
int N, M;
cin >> N >> M;
if (M == 1)
{
cout << 1 << endl;
return 0;
}
vector<vector<Mint>> ok(N + 1, vector<Mint>(M + 1));
vector<Mint> psum(N + 1);
for (int j = 2; j <= M; ++j)
ok[1][j] = 1;
psum[0] = 1;
psum[1] = M - 1;
for (int i = 2; i <= N; ++i)
{
for (int j = 2; j <= M; ++j)
{
ok[i][j] = psum[i - 1];
if (i >= j)
ok[i][j] -= psum[i - j] - ok[i - j][j];
psum[i] += ok[i][j];
}
}
cout << (Mint(M).pow(N) - psum[N]).val() << endl;
}