結果

問題 No.1889 K Consecutive Ks (Hard)
ユーザー akakimidoriakakimidori
提出日時 2022-03-21 00:12:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 755 ms / 6,000 ms
コード長 1,254 bytes
コンパイル時間 2,375 ms
コンパイル使用メモリ 118,196 KB
実行使用メモリ 15,036 KB
最終ジャッジ日時 2024-04-16 17:22:37
合計ジャッジ時間 12,811 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 755 ms
14,912 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 733 ms
14,692 KB
testcase_10 AC 746 ms
14,896 KB
testcase_11 AC 172 ms
6,572 KB
testcase_12 AC 347 ms
9,308 KB
testcase_13 AC 191 ms
7,312 KB
testcase_14 AC 353 ms
9,320 KB
testcase_15 AC 391 ms
10,344 KB
testcase_16 AC 747 ms
14,756 KB
testcase_17 AC 171 ms
6,728 KB
testcase_18 AC 733 ms
14,564 KB
testcase_19 AC 750 ms
14,924 KB
testcase_20 AC 753 ms
14,904 KB
testcase_21 AC 753 ms
15,032 KB
testcase_22 AC 753 ms
14,908 KB
testcase_23 AC 372 ms
10,084 KB
testcase_24 AC 754 ms
15,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/convolution>
#include <atcoder/modint>
#include <iostream>
#include <vector>

using namespace std;
using namespace atcoder;
using mint = modint998244353;

vector<mint> get(vector<mint> &a, int l, int r) {
    return {a.begin() + l, a.begin() + r};
}

int main(void) {
    int n, m;
    cin >> n >> m;
    vector<mint> ok(n + 1), ng(n + 1), a(n + 1), b(n + 1);
    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= n / i; ++j) {
            a[i * j] += 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        b[i] = mint(m - 1) * mint(m).pow(i - 1);
    }
    for (int i = 0; i <= n; ++i) {
        ok[i] = mint(m).pow(i);
    }
    auto dc = [&](auto self, int l, int r) {
        if (l + 1 == r) {
            ok[l] -= ng[l];
            return;
        }
        int m = (l + r) / 2;
        self(self, l, m);
        int n = r - l;
        auto x = convolution(get(ok, l, m), get(a, 0, n));
        auto y = convolution(get(ng, l, m), get(b, 0, n));
        for (int i = m; i < r; ++i) {
            ok[i] -= y[i - m + n / 2];
            ng[i] += x[i - m + n / 2];
        }
        self(self, m, r);
    };
    dc(dc, 0, n + 1);
    mint ans = mint(m).pow(n) - ok[n];
    cout << ans.val() << endl;
    return 0;
}
0