QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#708435#6522. Digit ModehhoppitreeWA 143ms4068kbC++172.4kb2024-11-03 22:15:072024-11-03 22:15:08

Judging History

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

  • [2024-11-03 22:15:08]
  • 评测
  • 测评结果:WA
  • 用时:143ms
  • 内存:4068kb
  • [2024-11-03 22:15:07]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 65, P = 1e9 + 7;

int fac[N], iFac[N], f[N], g[N];

int calc(int c1, vector<int> c2, int n) {
    if (*min_element(c2.begin(), c2.end()) < 0 || c1 > n) return 0;
    if (c1 + accumulate(c2.begin(), c2.end(), 0) < n) return 0;
    for (int i = 0; i <= n; ++i) f[i] = (i == c1 ? iFac[i] : 0);
    for (auto x : c2) {
        for (int i = 0; i <= n; ++i) g[i] = f[i], f[i] = 0;
        for (int i = 0; i <= n; ++i) {
            for (int j = 0; j <= x && j <= n - i; ++j) {
                f[i + j] = (f[i + j] + 1ll * g[i] * iFac[j]) % P;
            }
        }
    }
    return 1ll * f[n] * fac[n] % P;
}

long long pre[N];

signed main() {
    for (int i = fac[0] = 1; i <= 50; ++i) {
        fac[i] = 1ll * fac[i - 1] * i % P;
        iFac[i] = (i == 1 ? 1 : 1ll * (P - P / i) * iFac[P % i] % P);
    }
    for (int i = iFac[0] = 1; i <= 50; ++i) {
        iFac[i] = 1ll * iFac[i - 1] * iFac[i] % P;
    }
    for (int i = 1; i <= 50; ++i) {
        for (int j = 1; j <= 9; ++j) {
            for (int k = 1; k <= i; ++k) {
                vector<int> ts;
                for (int l = 0; l < 10; ++l) {
                    if (l != j) ts.push_back(k - (l > j));
                }
                pre[i] += j * calc(k, ts, i);
                --ts[0], pre[i] -= j * calc(k, ts, i - 1);
            }
        }
        pre[i] += pre[i - 1];
    }
    int T; scanf("%d", &T);
    while (T--) {
        string S; cin >> S;
        map<char, int> M;
        for (auto x : S) ++M[x];
        pair<int, int> mx = {0, 0};
        for (auto [x, y] : M) mx = max(mx, {y, x - '0'});
        int n = S.size();
        long long res = mx.second + pre[S.size() - 1];
        int ct[10];
        for (int i = 0; i < 10; ++i) ct[i] = 0;
        for (int i = 0; i <= n - 1; ++i) {
            for (int j = !i; j < S[i] - '0'; ++j) {
                for (int k = 1; k < 10; ++k) {
                    for (int l = 0; l <= n - i - 1; ++l) {
                        vector<int> ts;
                        for (int p = 0; p < 10; ++p) {
                            if (p != k) ts.push_back(ct[k] + (j == k) + l - ct[p] - (j == p) - (p > k));
                        }
                        res += k * calc(l, ts, n - i - 1);
                    }
                }
            }
            ++ct[S[i] - '0'];
        }
        printf("%lld\n", (res % P + P) % P);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 131ms
memory: 4068kb

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: 130ms
memory: 4068kb

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: 130ms
memory: 3792kb

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: 131ms
memory: 3864kb

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: 131ms
memory: 3792kb

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: 127ms
memory: 4056kb

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: 132ms
memory: 3768kb

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
Wrong Answer
time: 143ms
memory: 3856kb

input:

3
5014252832385738
8762796162648653
919997886706385

output:

444734152
719081256
481702888

result:

wrong answer 1st numbers differ - expected: '892033338', found: '444734152'