QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#304732#6522. Digit Modeucup-team2894#AC ✓171ms4292kbC++174.6kb2024-01-14 01:38:242024-01-14 01:38:25

Judging History

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

  • [2024-01-14 01:38:25]
  • 评测
  • 测评结果:AC
  • 用时:171ms
  • 内存:4292kb
  • [2024-01-14 01:38:24]
  • 提交

answer

#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(a) (a).begin(), (a).end()
#define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin())

using namespace std;

#ifdef ONPC
mt19937 rnd(223);
#else
mt19937 rnd(chrono::high_resolution_clock::now()
			.time_since_epoch().count());
#endif

#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)

using ll = long long;
using ld = double;

using uint = unsigned int;
using ull = unsigned long long;
template <uint MD> struct ModInt {
    using M = ModInt;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint((ull)v * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    bool operator!=(const M& r) const { return v != r.v; }
    M inv() const;
    friend istream& operator>>(istream& is, M& r) { ll x; is >> x; r = M(x); return is; }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};

template<uint MD>
ModInt<MD> pow(ModInt<MD> x, ll n) {
    ModInt<MD> r = 1;
    while (n) {
        if (n & 1) r *= x;
        x *= x;
        n >>= 1;
    }
    return r;
}

template<uint MD>
ModInt<MD> ModInt<MD>::inv() const { return pow(*this, MD - 2); }

using Mint = ModInt<int(1e9 + 7)>;
// using Mint = double;

const int maxn = 1e5 + 100, inf = 1e9 + 100;

using V = array<int, 10>;

Mint dp[11][52][52], pd[11][52][52];

Mint of[52], f[52];

void calc(V ap, int k, int real_mx) {
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    int mx = k + real_mx;
    for (int i = 1; i < 10; i++) {
        for (int j = 0; j <= k; j++)
            fill(dp[i][j], dp[i][j] + k + 1, 0);
        for (int s = 0; s <= k; s++)
            for (int m = 0; m <= mx; m++)
                if (dp[i - 1][s][m] != 0) {
                    Mint val = dp[i - 1][s][m];
                    for (int z = 0; z + s <= k; z++) {
                        dp[i][s + z][max(m, z + ap[i - 1])] += val * of[z];
                    }
                }
    }
    for (int i = 0; i < 10; i++)
        for (int j = 0; j <= k; j++)
            for (int z = 0; z < mx; z++)
                dp[i][j][z + 1] += dp[i][j][z];
}

Mint go(V ap, int k) {
//    cerr << "call ";
//    for (int i : ap)
//        cerr << i << ' ';
//    cerr << "k " << k << '\n';
    int real_mx = 0;
    for (int i : ap)
        real_mx = max(real_mx, i);
    reverse(all(ap));
    calc(ap, k, real_mx);
    swap(dp, pd);
    reverse(all(ap));
    calc(ap, k, real_mx);
    Mint ans = 0;
    for (int m = 0; m < 10; m++) {
        for (int v = 0; v <= k; v++) {
            for (int le = 0; le + v <= k; le++) {
                ans += Mint(m) * of[v] * dp[m][le][ap[m] + v] * pd[9 - m][k - le - v][ap[m] + v - 1];
            }
        }
    }
    ans *= f[k];
    return ans;
}

void solve() {
    Mint ans = 0;
    string s(50, '9');
    cin >> s;
    for (char &c : s)
        c -= 48;
    int n = s.size();
    f[0] = of[0] = 1;
    for (int i = 1; i <= n; i++) {
        f[i] = f[i - 1] * i;
        of[i] = Mint(1) / f[i];
    }
    for (int len = 1; len < n; len++) {
        for (int w = 1; w < 10; w++) {
            V ap{};
            ap[w]++;
            ans += go(ap, len - 1);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int w = (i == 0); w < s[i] + (i + 1 == n); w++) {
            V ap{};
            for (int j = 0; j < i; j++)
                ap[s[j]]++;
            ap[w]++;
            Mint vs = go(ap, n - i - 1);
//            cerr << "w " << w << ' ' << vs << '\n';
            ans += vs;
        }
    }
    cout << ans << '\n';
}

int main() {
#ifdef ONPC
    freopen("../a.in", "r", stdin);
//    freopen("../a.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed;
    cout.precision(20);
    int ts;
    cin >> ts;
    while (ts--)
        solve();
    cerr << "\n\nConsumed " << TIME << endl;
}

详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 3992kb

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

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: 9ms
memory: 4276kb

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: 10ms
memory: 4292kb

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: 10ms
memory: 3992kb

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: 10ms
memory: 4212kb

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: 11ms
memory: 4184kb

input:

7
7934351
8474057
1287369
5845624
7796773
5805755
7349121

output:

42465725
45668947
6716401
30094426
41554096
29861098
38756757

result:

ok 7 numbers

Test #8:

score: 0
Accepted
time: 17ms
memory: 4128kb

input:

3
5014252832385738
8762796162648653
919997886706385

output:

892033338
297722019
462512414

result:

ok 3 number(s): "892033338 297722019 462512414"

Test #9:

score: 0
Accepted
time: 27ms
memory: 4272kb

input:

2
775701797726112292362823101
75927988177061355614

output:

371275551
566830847

result:

ok 2 number(s): "371275551 566830847"

Test #10:

score: 0
Accepted
time: 125ms
memory: 4132kb

input:

1
65760982925996012426370962570581226245366145016666

output:

661063035

result:

ok 1 number(s): "661063035"

Test #11:

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

input:

1
62597468169905757754175023836706426691470692832490

output:

9983261

result:

ok 1 number(s): "9983261"

Test #12:

score: 0
Accepted
time: 130ms
memory: 4080kb

input:

1
78912847369504885593964702297317051208901751786824

output:

817123221

result:

ok 1 number(s): "817123221"

Test #13:

score: 0
Accepted
time: 171ms
memory: 4056kb

input:

1
99999999999999999999999999999999999999999999999999

output:

25251932

result:

ok 1 number(s): "25251932"

Test #14:

score: 0
Accepted
time: 119ms
memory: 4080kb

input:

1
999999999999999999999999999999999999999999999

output:

439421821

result:

ok 1 number(s): "439421821"

Test #15:

score: 0
Accepted
time: 78ms
memory: 4072kb

input:

1
9999999999999999999999999999999999999999

output:

387537647

result:

ok 1 number(s): "387537647"

Test #16:

score: 0
Accepted
time: 169ms
memory: 4076kb

input:

1
99999999999999999999999998889999898988888889998888

output:

909431898

result:

ok 1 number(s): "909431898"

Test #17:

score: 0
Accepted
time: 166ms
memory: 4052kb

input:

1
99999999999999999999999998989899988889989889999888

output:

289727470

result:

ok 1 number(s): "289727470"

Test #18:

score: 0
Accepted
time: 171ms
memory: 4156kb

input:

1
99999999999999999999999998998988898888898889898999

output:

962896416

result:

ok 1 number(s): "962896416"

Test #19:

score: 0
Accepted
time: 81ms
memory: 4128kb

input:

1
9999999999999999999989988898888989888899

output:

995903330

result:

ok 1 number(s): "995903330"

Test #20:

score: 0
Accepted
time: 80ms
memory: 4080kb

input:

1
9999999999999999999989999889889998998898

output:

385460258

result:

ok 1 number(s): "385460258"

Test #21:

score: 0
Accepted
time: 171ms
memory: 4124kb

input:

1
99999999999999999999999999999999999999999999999999

output:

25251932

result:

ok 1 number(s): "25251932"