結果

問題 No.1889 K Consecutive Ks (Hard)
ユーザー 👑 colognecologne
提出日時 2022-03-25 22:37:36
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 374 ms / 6,000 ms
コード長 1,122 bytes
コンパイル時間 4,875 ms
コンパイル使用メモリ 286,920 KB
実行使用メモリ 11,568 KB
最終ジャッジ日時 2023-08-04 09:35:30
合計ジャッジ時間 10,386 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 372 ms
11,396 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 367 ms
11,204 KB
testcase_11 AC 83 ms
5,520 KB
testcase_12 AC 170 ms
7,148 KB
testcase_13 AC 91 ms
5,788 KB
testcase_14 AC 173 ms
7,112 KB
testcase_15 AC 189 ms
8,408 KB
testcase_16 AC 367 ms
11,236 KB
testcase_17 AC 83 ms
5,604 KB
testcase_18 AC 360 ms
10,944 KB
testcase_19 AC 367 ms
11,124 KB
testcase_20 AC 371 ms
11,260 KB
testcase_21 AC 374 ms
11,260 KB
testcase_22 AC 372 ms
11,568 KB
testcase_23 AC 181 ms
7,860 KB
testcase_24 AC 372 ms
11,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0