QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#111457#6522. Digit ModeToboTL 1475ms3492kbC++201.8kb2023-06-07 10:05:482023-06-07 10:05:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-07 10:05:50]
  • 评测
  • 测评结果:TL
  • 用时:1475ms
  • 内存:3492kb
  • [2023-06-07 10:05:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define N 100005
#define mod 1'000'000'007

int dig[51], cnt;
int table[51] = {0, 45, 615, 6570, 63657,
                 597600, 5689830, 56017680, 564676515,
                 706253855, 53001921, 116607642, 807754616,
                 555253686, 93648429, 358785453, 214810078,
                 642432049, 158594480, 599067452, 311948107,
                 103373398, 86116420, 524897403, 907977314,
                 138576683, 44283636, 241998094, 583822532,
                 537947530, 636674358, 585550280, 414900917,
                 756538572, 442412153, 703712200, 837470764,
                 311869987, 733194120, 596841112, 387537647,
                 769854984, 977490984, 112225690, 117109110,
                 439421821, 374895741, 471922812, 10030060,
                 835556902, 25251932};

int dfs(vector<int> sta, int cur, int zero, int limit)
{
    if (zero && !limit)
        return table[cur];
    if (!cur)
    {
        int mx = *max_element(sta.begin(), sta.end()), ans = 0;
        for (int i = 0; i <= 9; i++)
            if (mx && sta[i] == mx)
                ans = i;
        return ans;
    }
    int res = 0;
    for (int i = 0; i <= (limit ? dig[cur] : 9); i++)
    {
        if (!zero || i)
            sta[i]++;
        res = (res + dfs(sta, cur - 1, zero && (i == 0), limit && (i == dig[cur]))) % mod;
        if (!zero || i)
            sta[i]--;
    }
    return res;
}
void solve()
{
    string s;
    cin >> s;
    cnt = 0;
    for (char c : s)
        dig[++cnt] = c - '0';
    reverse(dig + 1, dig + cnt + 1);
    cout << dfs(vector<int>(10, 0), cnt, 1, 1) << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    while (t--)
        solve();
}

详细

Test #1:

score: 100
Accepted
time: 42ms
memory: 3448kb

input:

5
9
99
999
99999
999999

output:

45
615
6570
597600
5689830

result:

ok 5 number(s): "45 615 6570 597600 5689830"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3488kb

input:

34
7
48
8
76
1
97
7
5
7
7
2
89
9
4
84
46
6
73
86
78
5
3
8
9
31
24
78
7
11
45
2
65
88
6

output:

28
236
36
420
1
597
28
15
28
28
3
525
45
10
484
221
21
399
500
435
15
6
36
45
145
104
435
28
47
215
3
341
516
21

result:

ok 34 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 3448kb

input:

16
935
888
429
370
499
881
285
162
178
948
205
858
573
249
773
615

output:

6009
5618
2456
2078
2905
5562
1603
887
993
6121
1174
5378
3333
1374
4724
3631

result:

ok 16 numbers

Test #4:

score: 0
Accepted
time: 4ms
memory: 3416kb

input:

12
1242
9985
6469
9310
4191
9497
3166
3495
9711
9698
4137
2257

output:

7292
63531
37910
58047
23987
59479
18076
19675
61184
61086
23672
12913

result:

ok 12 numbers

Test #5:

score: 0
Accepted
time: 16ms
memory: 3492kb

input:

10
61195
72739
10164
79164
57851
12326
29132
55992
67377
13873

output:

337575
408170
63792
450686
316513
70493
157773
305011
374163
77954

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 99ms
memory: 3396kb

input:

8
529983
127270
421121
291729
461233
695056
365028
271160

output:

2744573
687141
2160067
1500426
2359204
3705475
1851172
1381981

result:

ok 8 numbers

Test #7:

score: 0
Accepted
time: 1475ms
memory: 3428kb

input:

7
7934351
8474057
1287369
5845624
7796773
5805755
7349121

output:

42465725
45668947
6716401
30094426
41554096
29861098
38756757

result:

ok 7 numbers

Test #8:

score: -100
Time Limit Exceeded

input:

3
5014252832385738
8762796162648653
919997886706385

output:


result: