結果
問題 |
No.3242 Count 8 Included Numbers (Hard)
|
ユーザー |
![]() |
提出日時 | 2025-08-22 22:00:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,685 bytes |
コンパイル時間 | 4,092 ms |
コンパイル使用メモリ | 255,888 KB |
実行使用メモリ | 7,860 KB |
最終ジャッジ日時 | 2025-08-22 22:00:47 |
合計ジャッジ時間 | 9,436 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 6 WA * 14 |
ソースコード
#include "atcoder/fenwicktree.hpp" #include <bits/stdc++.h> #include <atcoder/all> using namespace std; using isize = size_t; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = long double; using p2 = pair<i64, i64>; using el = tuple<i64, i64, i64>; using mint = atcoder::modint998244353; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } i64 pow(i64 x, i64 n) { i64 res = 1; i64 t = x; while (n > 0) { if (n & 1) { res = res * t; } t = t * t; n >>= 1; } return res; } i64 pow(i64 x, i64 n, i64 m) { i64 res = 1; i64 t = x % m; while (n > 0) { if (n & 1) { res = res * t % m; } t = t * t % m; n >>= 1; } return res; } void _main() { string n; cin >> n; mint ans = 0; mint cnt = 0; vector<mint> s(n.size() + 1, 0); s[n.size()] = 1; for (i64 i = n.size() - 1; i >= 0; i--) { i64 x = n[i] - '0'; s[i] = s[i + 1] + x * mint(10).pow(n.size() - i - 1); } i64 seen = 1e18; for (i64 i = 0; i < n.size(); i++) { i64 x = n[i] - '0'; ans += cnt * mint(10).pow(n.size() - i - 1); if (x > 8) { ans += mint(10).pow(n.size() - i - 1); } else if (x == 8 && seen == 1e18) { ans += s[i + 1]; seen = i; } if (i > 0) { ans += mint(10).pow(n.size() - i - 1); } cnt = cnt * 9; if (i == 0) { if (x <= 8) cnt += x - 1; else cnt += x - 2; } else { if (seen >= i) { if (x <= 8) cnt += x; else cnt += x - 1; } cnt += 8; } } cout << ans.val() << "\n"; }