結果

問題 No.3242 Count 8 Included Numbers (Hard)
ユーザー The Forsaking
提出日時 2025-08-22 21:05:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 193,968 KB
実行使用メモリ 37,800 KB
最終ジャッジ日時 2025-08-22 21:05:33
合計ジャッジ時間 3,595 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |     scanf("%s", s + 1);
      |     ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f;
ll res;
int n, m, cnt, w[N];

char s[N];
ll f[N], g[N];

int main() {
    g[0] = f[0] = 1;
    for (int i = 1; i < N; i++) f[i] = f[i - 1] * 9 % MOD, g[i] = g[i - 1] * 10 % MOD;
    scanf("%s", s + 1);
    n = strlen(s + 1);
    bool flag = 0;
    for (int i = 1; i < n + 1; i++) {
        for (int j = 0; j < s[i] - '0'; j++) {
            if (flag || j == 8) res = (res + g[n - i]) % MOD;
            else res = (res + g[n - i] - f[n - i] + MOD) % MOD;
        }
        flag |= s[i] == '8';
    }
    for (int i = 1; i < n + 1; i++)
        if (s[i] == '8') {
            res = (res + 1) % MOD;
            break;
        }
    printf("%lld\n", res);
    return 0;
}
0