QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#426334#6741. DigitrgnerdplayerAC ✓1412ms5136kbC++203.7kb2024-05-31 03:48:042024-05-31 03:48:05

Judging History

你现在查看的是最新测评结果

  • [2024-05-31 03:48:05]
  • 评测
  • 测评结果:AC
  • 用时:1412ms
  • 内存:5136kb
  • [2024-05-31 03:48:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
using u64 = unsigned long long;

template <int P>
struct Modint {
    int v;

    constexpr Modint() : v(0) {}
    constexpr Modint(i64 v_) : v(v_ % P) {
        if (v < 0) {
            v += P;
        }
    }
    constexpr explicit operator int() const { return v; }
    constexpr friend ostream& operator<<(ostream &out, Modint n) {
        return out << int(n);
    }
    constexpr friend istream& operator>>(istream &in, Modint &n) {
        i64 v;
        in >> v;
        n = Modint(v);
        return in;
    }

    constexpr friend bool operator==(Modint a, Modint b) {
        return a.v == b.v;
    }
    constexpr friend bool operator!=(Modint a, Modint b) {
        return a.v != b.v;
    }

    constexpr Modint operator-() {
        Modint res;
        res.v = v ? P - v : 0;
        return res;
    }

    constexpr Modint& operator++() {
        v++;
        if (v == P) v = 0;
        return *this;
    }
    constexpr Modint& operator--() {
        if (v == 0) v = P;
        v--;
        return *this;
    }
    constexpr Modint& operator+=(Modint o) {
        v -= P - o.v;
        v = (v < 0) ? v + P : v;
        return *this;
    }
    constexpr Modint& operator-=(Modint o) {
        v -= o.v;
        v = (v < 0) ? v + P : v;
        return *this;
    }
    constexpr Modint& operator*=(Modint o) {
        v = 1LL * v * o.v % P;
        return *this;
    }
    constexpr Modint& operator/=(Modint o) { return *this *= o.inv(); }

    constexpr friend Modint operator++(Modint &a, int) {
        Modint r = a;
        ++a;
        return r;
    }
    constexpr friend Modint operator--(Modint &a, int) {
        Modint r = a;
        --a;
        return r;
    }

    constexpr friend Modint operator+(Modint a, Modint b) {
        return Modint(a) += b;
    }
    constexpr friend Modint operator-(Modint a, Modint b) {
        return Modint(a) -= b;
    }
    constexpr friend Modint operator*(Modint a, Modint b) {
        return Modint(a) *= b;
    }
    constexpr friend Modint operator/(Modint a, Modint b) {
        return Modint(a) /= b;
    }

    constexpr Modint qpow(i64 p) {
        Modint res = 1, x = v;
        while (p > 0) {
            if (p & 1) { res *= x; }
            x *= x;
            p >>= 1;
        }
        return res;
    }
    constexpr Modint inv() {
        return qpow(P - 2);
    }
};

constexpr int P = 998244353;
using Mint = Modint<P>;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    vector<Mint> inv(21);
    for (int i = 1; i <= 20; i++) {
        inv[i] = i == 1 ? 1 : -P / i * inv[P % i];
    }

    int t;
    cin >> t;

    auto solve = [&]() {
        u64 n, N;
        cin >> n >> N;

        unordered_map<u64, Mint> memo;

        auto dp = [&](auto dp, u64 n) -> Mint {
            if (n > N) {
                return 0;
            }

            if (memo.count(n)) {
                return memo[n];
            }

            u64 x = n;
            int zeros = 0, digits = 0;
            Mint sum = 0;

            // dp[n] = 1 + (dp[n] * zeros + sum) / digits

            while (x > 0) {
                int t = x % 10;
                digits++;
                if (t == 0) {
                    zeros++;
                } else {
                    sum += dp(dp, n * (t + 1));
                }
                x /= 10;
            }

            return memo[n] = (digits + sum) * inv[digits - zeros];
        };

        cout << dp(dp, n) << '\n';
    };

    while (t--) {
        solve();
    }
    
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

input:

3
1 10
1 100
1 1000

output:

3
4
942786340

result:

ok 3 number(s): "3 4 942786340"

Test #2:

score: 0
Accepted
time: 946ms
memory: 4560kb

input:

200
6093 473302679260560320
8548 407261659389622784
643 187875386337017408
8115 804844129595563776
3331 457909423622471360
8554 769878068775393152
2189 248771553604839360
7395 486014798136226944
8022 834223266052054400
9218 291007794161740672
8431 738787973811775616
1829 183591119896739584
816 23406...

output:

401752224
25564055
349247348
24571488
454552241
293307892
841921314
316896313
340265070
679232017
880794571
220757927
783764236
593413719
368463075
771186516
780654585
3628414
827863355
617858224
868927625
446978548
351494058
130284374
125073939
38120850
748432314
277667083
183850680
235708406
51111...

result:

ok 200 numbers

Test #3:

score: 0
Accepted
time: 128ms
memory: 4628kb

input:

200
3043059018339257 22277869996577613
9995869516 503712331451
389592 72563932968
3520234478258 476959582208156
77586585 711120211545804458
77846354 2243822883730937
9937954107 8390895135555
39032 603567
7739 4682236745217490
12277973519 7136059697857236
7264388 607094625
66205992799 4030219735546
3...

output:

108920162
651706276
549514920
440563412
796578996
851857830
191543780
540715694
549223125
380090491
553492005
247956062
582309209
67430878
174114881
1
669072219
981051601
561639793
304668111
397423058
607062211
8458982
479445466
287831358
913943402
533482140
801644611
519995972
239199505
587671914
2...

result:

ok 200 numbers

Test #4:

score: 0
Accepted
time: 1371ms
memory: 5136kb

input:

200
58 999999999999997440
75 999999999999999872
52 999999999999997696
85 999999999999999360
12 999999999999999488
77 999999999999999232
80 999999999999999232
36 999999999999997184
51 999999999999998720
79 999999999999997440
76 999999999999998592
90 999999999999997696
32 999999999999998336
67 9999999...

output:

603520497
574767370
222266238
241598642
627473669
958322466
776467011
836867165
317725053
772230956
80008248
170
205889745
956913345
252066713
183389093
251365357
387390363
836867165
660512518
265265911
574767370
317725053
620530996
15655429
247241569
103698881
940321220
960908253
960908253
66051251...

result:

ok 200 numbers

Test #5:

score: 0
Accepted
time: 441ms
memory: 4784kb

input:

200
509411 999999999999999232
33801448 999999999999998720
65 999999999999998208
6 999999999999997184
404287 999999999999999360
800418816395 999999999999999232
44589090134507 999999999999997312
2008080 999999999999999360
13 999999999999998976
87 999999999999999872
206327851576605 999999999999999744
3...

output:

883813861
221710219
620530996
252066714
168038945
932330901
77414612
443356611
1883978
608670663
568648025
891202485
151357997
793825022
180372901
749235099
391331669
890726608
103698881
258627374
738512765
18273750
771644777
916674174
110687232
890972839
85823452
799141196
739829892
675630993
44879...

result:

ok 200 numbers

Test #6:

score: 0
Accepted
time: 1412ms
memory: 4956kb

input:

200
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 10000000...

output:

252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
...

result:

ok 200 numbers