結果

問題 No.2772 Appearing Even Times
ユーザー Abhishek ChoudharyAbhishek Choudhary
提出日時 2024-05-31 23:06:28
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 233 ms
323,280 KB
testcase_01 AC 232 ms
323,276 KB
testcase_02 AC 235 ms
323,516 KB
testcase_03 AC 230 ms
323,312 KB
testcase_04 AC 233 ms
323,448 KB
testcase_05 AC 235 ms
323,336 KB
testcase_06 AC 235 ms
323,476 KB
testcase_07 AC 231 ms
323,352 KB
testcase_08 AC 1,165 ms
324,384 KB
testcase_09 AC 1,245 ms
324,316 KB
testcase_10 AC 233 ms
323,400 KB
testcase_11 AC 236 ms
323,356 KB
testcase_12 AC 1,169 ms
324,444 KB
testcase_13 AC 1,185 ms
324,336 KB
testcase_14 AC 1,168 ms
324,328 KB
testcase_15 AC 1,180 ms
324,328 KB
testcase_16 AC 1,164 ms
324,388 KB
testcase_17 AC 1,165 ms
324,460 KB
testcase_18 AC 1,169 ms
324,352 KB
testcase_19 AC 1,158 ms
324,200 KB
testcase_20 AC 1,166 ms
324,468 KB
testcase_21 AC 1,167 ms
324,256 KB
権限があれば一括ダウンロードができます

ソースコード

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