結果

問題 No.1889 K Consecutive Ks (Hard)
ユーザー akakimidoriakakimidori
提出日時 2022-03-20 20:32:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,213 bytes
コンパイル時間 2,494 ms
コンパイル使用メモリ 118,348 KB
実行使用メモリ 15,248 KB
最終ジャッジ日時 2024-04-16 13:47:44
合計ジャッジ時間 13,562 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 724 ms
14,912 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 705 ms
14,692 KB
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 RE -
testcase_17 WA -
testcase_18 WA -
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 729 ms
15,164 KB
testcase_22 WA -
testcase_23 RE -
testcase_24 AC 732 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;
        }
        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