結果

問題 No.2437 Fragile Multiples of 11
ユーザー ebi_flyebi_fly
提出日時 2023-08-11 18:12:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 462 ms / 2,000 ms
コード長 1,797 bytes
コンパイル時間 2,743 ms
コンパイル使用メモリ 219,496 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-29 09:43:09
合計ジャッジ時間 11,398 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,144 KB
testcase_01 AC 18 ms
6,144 KB
testcase_02 AC 52 ms
6,016 KB
testcase_03 AC 443 ms
6,016 KB
testcase_04 AC 429 ms
6,144 KB
testcase_05 AC 444 ms
6,016 KB
testcase_06 AC 441 ms
6,144 KB
testcase_07 AC 447 ms
6,016 KB
testcase_08 AC 454 ms
6,016 KB
testcase_09 AC 462 ms
6,144 KB
testcase_10 AC 440 ms
6,016 KB
testcase_11 AC 437 ms
6,144 KB
testcase_12 AC 430 ms
6,016 KB
testcase_13 AC 430 ms
6,016 KB
testcase_14 AC 432 ms
6,016 KB
testcase_15 AC 9 ms
6,144 KB
testcase_16 AC 9 ms
6,016 KB
testcase_17 AC 9 ms
6,144 KB
testcase_18 AC 9 ms
6,144 KB
testcase_19 AC 9 ms
6,144 KB
testcase_20 AC 9 ms
6,016 KB
testcase_21 AC 9 ms
6,144 KB
testcase_22 AC 9 ms
6,144 KB
testcase_23 AC 9 ms
6,016 KB
testcase_24 AC 98 ms
6,016 KB
testcase_25 AC 51 ms
6,016 KB
testcase_26 AC 47 ms
6,016 KB
testcase_27 AC 96 ms
6,144 KB
testcase_28 AC 430 ms
6,016 KB
testcase_29 AC 384 ms
6,016 KB
testcase_30 AC 384 ms
6,016 KB
testcase_31 AC 351 ms
6,016 KB
testcase_32 AC 271 ms
6,016 KB
testcase_33 AC 96 ms
6,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>

#define rep(i, s, n) for (int i = int(s); i < int(n); i++)

using mint = atcoder::modint998244353;

int main() {
    int n;
    std::string x;
    std::cin >> n >> x;
    const int m = 11;
    std::vector dp(m, std::vector(1 << m, std::vector<mint>(2, 0)));
    bool is_top = true;
    for (auto c : x) {
        std::vector nxt(m, std::vector(1 << m, std::vector<mint>(2, 0)));
        rep(i, 0, m) {
            rep(bit, 0, 1 << m) {
                int ret = 0;
                rep(j, 0, m) {
                    if ((bit >> j) & 1) {
                        ret |= 1 << ((j * 10) % m);
                    }
                }
                rep(d, 0, 10) {
                    int nxt_bit = ret | (1 << i);
                    nxt[(i * 10 + d) % m][nxt_bit][0] += dp[i][bit][0];
                    if (d < c - '0') {
                        nxt[(i * 10 + d) % m][nxt_bit][0] += dp[i][bit][1];
                    } else if (d == c - '0') {
                        nxt[(i * 10 + d) % m][nxt_bit][1] += dp[i][bit][1];
                    }
                    ret <<= 1;
                    if ((ret >> m) & 1) {
                        ret ^= (1 << m) | 1;
                    }
                }
            }
        }
        rep(i, 1, 10) {
            if (is_top) {
                if (i == c - '0')
                    nxt[i][1][1]++;
                else if (i < c - '0')
                    nxt[i][1][0]++;
                else
                    continue;
            } else
                nxt[i][1][0]++;
        }
        dp = nxt;
        is_top = false;
    }
    mint ans = 0;
    rep(bit, 0, 1 << m) {
        if (bit & 1) continue;
        ans += dp[0][bit][0] + dp[0][bit][1];
    }
    std::cout << ans.val() << '\n';
}
0