結果

問題 No.3242 Count 8 Included Numbers (Hard)
ユーザー AngrySadEight
提出日時 2025-06-17 08:49:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 73,720 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-06-18 09:10:36
合計ジャッジ時間 2,209 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

const ll mod = 998244353;

int main() {
    string N;
    cin >> N;
    ll len = N.size();

    ll cnt = 0;
    for (ll i = 0; i < len; i++) {
        cnt *= 10;
        cnt += (ll)(N[i] - '0');
        cnt %= mod;
    }

    string N2 = N;
    for (ll i = 0; i < len; i++) {
        if (N2[i] == '8') {
            N2[i] = '7';
            for (ll j = i + 1; j < len; j++) {
                N2[j] = '9';
            }
            break;
        }
    }
    ll cnt2 = 0;
    for (ll i = 0; i < len; i++) {
        cnt2 *= 9;
        if (N2[i] == '9') {
            cnt2 += 8;
        } else {
            cnt2 += (ll)(N2[i] - '0');
        }
        cnt2 %= mod;
    }
    cout << (cnt - cnt2 + mod) % mod << endl;
}
0