結果
問題 |
No.3242 Count 8 Included Numbers (Hard)
|
ユーザー |
|
提出日時 | 2025-10-13 16:43:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 262 ms / 2,000 ms |
コード長 | 878 bytes |
コンパイル時間 | 4,103 ms |
コンパイル使用メモリ | 251,516 KB |
実行使用メモリ | 115,384 KB |
最終ジャッジ日時 | 2025-10-13 16:43:19 |
合計ジャッジ時間 | 8,210 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; #define rep(i, n) for(int i =0; i < (n); i++) using ll = long long int; string s; ll dp[888888][2][2]; ll f(int pos, bool tight, bool has8) { if (pos == s.size()) { return has8; } if (dp[pos][tight][has8] != -1) return dp[pos][tight][has8]; ll res = 0; int limit = tight ? (s[pos] - '0') : 9; for (int d = 0; d <= limit; d++) { bool new_tight = tight && (d == limit); bool new_has8 = has8 || (d == 8); res += f(pos + 1, new_tight, new_has8); res %= 998244353; } return dp[pos][tight][has8] = res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("input.txt", "r", stdin); cin >> s; memset(dp, -1, sizeof(dp)); cout << f(0, true, false) << endl; return 0; }