結果
| 問題 |
No.3242 Count 8 Included Numbers (Hard)
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2025-08-16 10:56:59 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 797 bytes |
| コンパイル時間 | 277 ms |
| コンパイル使用メモリ | 27,724 KB |
| 実行使用メモリ | 25,736 KB |
| 最終ジャッジ日時 | 2025-08-16 10:57:02 |
| 合計ジャッジ時間 | 1,991 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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];
| ^~~
main.c: In function ‘main’:
main.c:22:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | scanf("%s", N);
| ^~~~~~~~~~~~~~
ソースコード
#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];
scanf("%s", N);
int i, l;
for (l = 0; N[l] != 0; l++);
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;
}