結果
| 問題 | No.2772 Appearing Even Times |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-31 23:06:28 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 683 ms / 4,000 ms |
| コード長 | 970 bytes |
| 記録 | |
| コンパイル時間 | 2,191 ms |
| コンパイル使用メモリ | 331,152 KB |
| 実行使用メモリ | 324,480 KB |
| 最終ジャッジ日時 | 2026-05-27 19:57:41 |
| 合計ジャッジ時間 | 14,799 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#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;
}