結果
問題 |
No.3242 Count 8 Included Numbers (Hard)
|
ユーザー |
👑 |
提出日時 | 2025-08-18 09:43:57 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 465 ms |
コンパイル使用メモリ | 27,600 KB |
実行使用メモリ | 25,772 KB |
最終ジャッジ日時 | 2025-08-18 09:44:00 |
合計ジャッジ時間 | 2,690 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
コンパイルメッセージ
main.c:4:20: warning: built-in function ‘pow’ declared as non-function [-Wbuiltin-declaration-mismatch] 4 | long long ans = 0, pow[2][1000000], val[1000000]; | ^~~
ソースコード
#include <stdio.h> const int Mod = 998244353; long long ans = 0, pow[2][1000000], val[1000000]; void recursion(char N[], int l, int k) { if (k == l) return; int x = N[k] - '0'; if (x > 8) ans += pow[0][l-k-1]; else if (x == 8) ans += val[l-k-1] + 1; int i; for (i = 0; i < x && i < 8; i++) ans += pow[0][l-k-1] - pow[1][l-k-1] + Mod; if (x != 8) recursion(N, l, k + 1); } int main() { char N[1000000]; if (scanf("%s", N) != 1) return -1; if (scanf("%s", N) != EOF) return -1; int i, l; for (l = 0; N[l] != 0; l++) if (N[l] < '0' || N[l] > '9') return -1; if ((l == 1 && N[0] == '0') || l < 1 || l > 888888) return -1; for (i = 1, pow[0][0] = 1, pow[1][0] = 1; i <= l; i++) { pow[0][i] = pow[0][i-1] * 10 % Mod; pow[1][i] = pow[1][i-1] * 9 % Mod; } for (i = l - 1, val[0] = 0; i >= 0; i--) val[l-i] = (val[l-i-1] + (N[i] - '0') * pow[0][l-i-1]) % Mod; recursion(N, l, 0); printf("%lld\n", ans % Mod); fflush(stdout); return 0; }