結果

問題 No.2413 Multiple of 99
ユーザー AngrySadEightAngrySadEight
提出日時 2023-07-20 22:43:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,952 ms / 8,000 ms
コード長 2,497 bytes
コンパイル時間 4,738 ms
コンパイル使用メモリ 143,300 KB
実行使用メモリ 49,024 KB
最終ジャッジ日時 2023-10-21 00:54:34
合計ジャッジ時間 26,426 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 18 ms
4,348 KB
testcase_05 AC 48 ms
4,856 KB
testcase_06 AC 39 ms
4,556 KB
testcase_07 AC 1,790 ms
47,916 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1,765 ms
47,916 KB
testcase_10 AC 1,802 ms
47,916 KB
testcase_11 AC 1,899 ms
49,024 KB
testcase_12 AC 1,800 ms
47,916 KB
testcase_13 AC 1,803 ms
47,916 KB
testcase_14 AC 1,805 ms
47,916 KB
testcase_15 AC 1,802 ms
47,916 KB
testcase_16 AC 872 ms
26,356 KB
testcase_17 AC 880 ms
25,340 KB
testcase_18 AC 1,952 ms
45,516 KB
testcase_19 AC 109 ms
6,560 KB
testcase_20 AC 48 ms
5,048 KB
testcase_21 AC 104 ms
6,288 KB
testcase_22 AC 1,913 ms
45,580 KB
testcase_23 AC 206 ms
8,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <atcoder/convolution>
#include <iostream>
#include <vector>
using namespace std;
using namespace atcoder;
using ll = long long;

ll mod = 998244353;

ll my_pow(ll x, ll n, ll mod) {
    //  繰り返し二乗法.x^nをmodで割った余り.
    ll ret;
    if (n == 0) {
        ret = 1;
    } else if (n % 2 == 1) {
        ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod;
    } else {
        ret = my_pow((x * x) % mod, n / 2, mod);
    }
    return ret;
}

ll inv(ll x, ll mod) { return my_pow(x, mod - 2, mod); }

vector<ll> pow_poly(vector<ll> &vec, ll n, ll mod) {
    vector<ll> ret(0);
    if (n == 0) {
        ret.push_back(1);
    } else if (n % 2 == 1) {
        vector<ll> vec_conv = convolution<998244353>(vec, vec);
        vector<ll> vec_tmp = pow_poly(vec_conv, n / 2, mod);
        vector<ll> vec_nxt = convolution<998244353>(vec, vec_tmp);
        for (ll i = 0; i < vec_nxt.size(); i++) {
            ret.push_back(vec_nxt[i]);
        }
    } else {
        vector<ll> vec_conv = convolution<998244353>(vec, vec);
        vector<ll> vec_nxt = pow_poly(vec_conv, n / 2, mod);
        for (ll i = 0; i < vec_nxt.size(); i++) {
            ret.push_back(vec_nxt[i]);
        }
    }
    return ret;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> vec(10);
    for (ll i = 0; i < 10; i++) {
        vec[i] = 1;
    }
    vector<ll> ans_vec1 = pow_poly(vec, (N + 1) / 2, mod);
    vector<ll> ans_vec2 = pow_poly(vec, N / 2, mod);
    ll len1 = ans_vec1.size();
    ll len2 = ans_vec2.size();
    vector<ll> numsum(N * 9 + 2, 0);
    for (ll i = 0; i < 11; i++) {
        vector<ll> mod_vec1(len1);
        for (ll j = 0; j < len1; j++) {
            if (j % 11 == i) {
                mod_vec1[j] = ans_vec1[j];
            } else {
                mod_vec1[j] = 0;
            }
        }
        vector<ll> mod_vec2(len2);
        for (ll j = 0; j < len2; j++) {
            if (j % 11 == i) {
                mod_vec2[j] = ans_vec2[j];
            } else {
                mod_vec2[j] = 0;
            }
        }
        vector<ll> conv = convolution<998244353>(mod_vec1, mod_vec2);
        for (ll j = 0; j < conv.size(); j++) {
            numsum[j] = (numsum[j] + conv[j]) % mod;
        }
    }
    ll ans = 0;
    for (ll i = 0; i <= N * 9; i += 9) {
        ans = (ans + (numsum[i] * my_pow(i, K, mod))) % mod;
    }
    cout << ans << endl;
}
0