QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111459#6522. Digit ModeToboAC ✓292ms3588kbC++202.5kb2023-06-07 10:19:192023-06-07 10:19:21

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:19:21]
  • 评测
  • 测评结果:AC
  • 用时:292ms
  • 内存:3588kb
  • [2023-06-07 10:19:19]
  • 提交

answer

#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<(x)<<endl
using namespace std;
typedef long long ll;
const int MAXN=(int)1e5+5;
const int MOD=(int)1e9+7;
string s;
int a[55],n;
ll comb[55][55];
int dp[55],tmp[55];
int ti[10];
ll ans;
int tbl[]={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};
void dfs(int pos,int flag){
    if(pos==0){
        int x=0;
        for(int i=1;i<=9;i++)if(ti[i]>=ti[x])x=i;
        ans+=x;
        return;
    }
    if(!flag){
        int ma=0,N=pos;
        for(int i=0;i<=9;i++)ma=max(ma,ti[i]),N+=ti[i];
        for(int x=1;x<=9;x++){
            for(int y=0;y<=pos;y++){
                if(ti[x]+y<ma)continue;
                if((ti[x]+y)*(x+1)+(ti[x]+y-1)*(9-x)<N)continue;
                fill(dp,dp+1+pos,0);
                dp[y]=comb[pos][y];
                for(int i=0;i<=9;i++){
                    if(i==x)continue;
                    fill(tmp,tmp+1+pos,0);
                    bool flag=1;
                    for(int j=0;j+y<=pos;j++){
                        int de=j+ti[i]-(y+ti[x]);
                        if(de>0||(x<i&&de==0))break;
                        for(int k=j;k<=pos;k++){
                            tmp[k]=(tmp[k]+dp[k-j]*comb[pos-k+j][j])%MOD;
                        }
                    }
                    swap(tmp,dp);
                }
                ans+=(ll)x*dp[pos];
            }
        }
        ans%=MOD;
        return;
    }
    int ed=flag?a[pos]:9;
    for(int i=0;i<=ed;i++){
        ti[i]++;
        dfs(pos-1,flag&&i==ed);
        ti[i]--;
    }
}
void solve(){
    ans=0;
    cin>>s;
    n=s.size();
    ans=tbl[n-1];
    for(int i=1;i<=n;i++)a[i]=s[n-i]-'0';
    for(int i=1;i<=a[n];i++){
        ti[i]++;
        dfs(n-1,i==a[n]);
        ti[i]--;
    }
    cout<<ans<<"\n";
}
int main()
{
    for(int i=0;i<=50;i++){
        comb[i][0]=1;
        for(int j=1;j<=i;j++){
            comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%MOD;
        }
    }
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3348kb

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: 3340kb

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: 3444kb

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

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

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

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

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

input:

3
5014252832385738
8762796162648653
919997886706385

output:

892033338
297722019
462512414

result:

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

Test #9:

score: 0
Accepted
time: 30ms
memory: 3444kb

input:

2
775701797726112292362823101
75927988177061355614

output:

371275551
566830847

result:

ok 2 number(s): "371275551 566830847"

Test #10:

score: 0
Accepted
time: 199ms
memory: 3440kb

input:

1
65760982925996012426370962570581226245366145016666

output:

661063035

result:

ok 1 number(s): "661063035"

Test #11:

score: 0
Accepted
time: 208ms
memory: 3380kb

input:

1
62597468169905757754175023836706426691470692832490

output:

9983261

result:

ok 1 number(s): "9983261"

Test #12:

score: 0
Accepted
time: 214ms
memory: 3444kb

input:

1
78912847369504885593964702297317051208901751786824

output:

817123221

result:

ok 1 number(s): "817123221"

Test #13:

score: 0
Accepted
time: 282ms
memory: 3440kb

input:

1
99999999999999999999999999999999999999999999999999

output:

25251932

result:

ok 1 number(s): "25251932"

Test #14:

score: 0
Accepted
time: 194ms
memory: 3588kb

input:

1
999999999999999999999999999999999999999999999

output:

439421821

result:

ok 1 number(s): "439421821"

Test #15:

score: 0
Accepted
time: 118ms
memory: 3544kb

input:

1
9999999999999999999999999999999999999999

output:

387537647

result:

ok 1 number(s): "387537647"

Test #16:

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

input:

1
99999999999999999999999998889999898988888889998888

output:

909431898

result:

ok 1 number(s): "909431898"

Test #17:

score: 0
Accepted
time: 282ms
memory: 3440kb

input:

1
99999999999999999999999998989899988889989889999888

output:

289727470

result:

ok 1 number(s): "289727470"

Test #18:

score: 0
Accepted
time: 292ms
memory: 3444kb

input:

1
99999999999999999999999998998988898888898889898999

output:

962896416

result:

ok 1 number(s): "962896416"

Test #19:

score: 0
Accepted
time: 122ms
memory: 3584kb

input:

1
9999999999999999999989988898888989888899

output:

995903330

result:

ok 1 number(s): "995903330"

Test #20:

score: 0
Accepted
time: 120ms
memory: 3436kb

input:

1
9999999999999999999989999889889998998898

output:

385460258

result:

ok 1 number(s): "385460258"

Test #21:

score: 0
Accepted
time: 285ms
memory: 3444kb

input:

1
99999999999999999999999999999999999999999999999999

output:

25251932

result:

ok 1 number(s): "25251932"