結果

問題 No.2772 Appearing Even Times
ユーザー Abhishek Choudhary
提出日時 2024-05-31 23:06:28
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,245 ms / 4,000 ms
コード長 970 bytes
コンパイル時間 5,119 ms
コンパイル使用メモリ 273,132 KB
実行使用メモリ 324,468 KB
最終ジャッジ日時 2024-12-21 01:27:07
合計ジャッジ時間 23,047 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

const int M = 998244353;
const int MAX_LENGTH = 10001;
const int MAX_TIGHT = 2;
const int MAX_NZSEEN = 2;
const int MAX_MASK = (1 << 11) - 1;

int dp[MAX_LENGTH][MAX_TIGHT][MAX_NZSEEN][MAX_MASK];

int count(const std::string& num, int i, bool tight, bool nzseen, int mask) {
    if (i >= static_cast<int>(num.length())) {
        return (mask == 0 && nzseen);
    }

    int& result = dp[i][tight][nzseen][mask];
    if (result != -1) {
        return result;
    }

    int maxd = 9;
    if (tight) {
        maxd = num[i] - '0';
    }

    result = 0;
    for (int d = 0; d <= maxd; d++) {
        bool newNzseen = nzseen || (d != 0);
        result += count(num, i + 1, tight && (d == maxd), newNzseen, mask ^ (1 << d) * newNzseen);
        result %= M;
    }

    return result;
}

int main() {
    std::string n;
    std::cin >> n;

    memset(dp, -1, sizeof(dp));
    std::cout << count(n, 0, true, false, 0) << std::endl;
    return 0;
}
0