結果

問題 No.2772 Appearing Even Times
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-05-31 23:40:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,900 ms / 4,000 ms
コード長 1,337 bytes
コンパイル時間 2,829 ms
コンパイル使用メモリ 214,108 KB
実行使用メモリ 166,016 KB
最終ジャッジ日時 2024-05-31 23:40:39
合計ジャッジ時間 21,436 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1,014 ms
166,016 KB
testcase_09 AC 1,900 ms
166,016 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1,443 ms
165,760 KB
testcase_13 AC 1,448 ms
164,992 KB
testcase_14 AC 1,441 ms
165,504 KB
testcase_15 AC 1,437 ms
165,120 KB
testcase_16 AC 1,470 ms
165,888 KB
testcase_17 AC 1,439 ms
165,888 KB
testcase_18 AC 1,453 ms
165,760 KB
testcase_19 AC 1,441 ms
165,376 KB
testcase_20 AC 1,413 ms
163,200 KB
testcase_21 AC 1,430 ms
163,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint998244353;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    string num;
    cin >> num;
    vector<int> n;
    for (char c : num) {
        n.push_back(c - '0');
    }
    int l = n.size();
    vector dp(l + 1, vector(2, vector(2, vector<mint>(1024, 0))));
    dp[0][0][0][0] = 1;
    for (int i = 0; i < l; i++) {
        for (int smaller = 0; smaller < 2; smaller++) {
            for (int non_zero = 0; non_zero < 2; non_zero++) {
                for (int msk = 0; msk < 1024; msk++) {
                    for (int x = 0; x <= (smaller ? 9 : n[i]); x++) {
                        if (x == 0 && non_zero == 0) {
                            dp[i + 1][smaller || (x < n[i])][0][msk] +=
                                dp[i][smaller][non_zero][msk];
                        } else {
                            dp[i + 1][smaller || (x < n[i])][1]
                              [msk ^ (1 << x)] += dp[i][smaller][non_zero][msk];
                        }
                    }
                }
            }
        }
    }
    mint ans = 0;
    for (int non_zero = 0; non_zero < 2; non_zero++) {
        ans += dp[l][non_zero][1][0];
    }
    cout << ans.val() << endl;
}
0