結果
| 問題 |
No.1889 K Consecutive Ks (Hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-25 22:37:36 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 375 ms / 6,000 ms |
| コード長 | 1,122 bytes |
| コンパイル時間 | 4,917 ms |
| コンパイル使用メモリ | 289,928 KB |
| 実行使用メモリ | 11,468 KB |
| 最終ジャッジ日時 | 2024-10-14 06:34:41 |
| 合計ジャッジ時間 | 10,045 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#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<Mint> C(N + 1, 0);
for (int i = 2; i <= M; ++i)
{
for (int base = 1; base <= N; base += i)
{
if (base <= N)
C[base]++;
if (base + i - 1 <= N)
C[base + i - 1]--;
}
}
C.erase(C.begin());
vector<Mint> D(N + 1, 0);
D[0] = 1;
function<void(int, int)> DnC = [&](int L, int R)
{
if (L == R)
return;
int M = (L + R) / 2;
DnC(L, M);
vector<Mint> V(D.begin() + L, D.begin() + M + 1);
vector<Mint> Co(C.begin(), C.begin() + (R - L));
vector<Mint> ans = atcoder::convolution(V, Co);
for (int i = M + 1; i <= R; ++i)
D[i] += ans[i - (M + 1) + (int)V.size() - 1];
DnC(M + 1, R);
};
DnC(0, N);
cout << (Mint(M).pow(N) - D.back()).val() << endl;
}