QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196573 | #6522. Digit Mode | ucup-team870# | WA | 142ms | 7240kb | C++14 | 2.1kb | 2023-10-01 19:32:29 | 2023-10-01 19:32:29 |
Judging History
answer
#include <bits/stdc++.h>
#define For(i,l,r) for(int i=l; i<=r; i++)
#define per(i,l,r) for(int i=l;i>=r;i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
const int mo=998244353;
int a[11]; ll dp[13][53][13][53];
ll c[53][53];
void init(){
For(i,0,50) c[i][0]=1;
For(i,1,50) For(j,1,i) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mo;
}
ll cal(int n){
int ma=-1,ii;
For(i,0,9) if (a[i]>=ma) ma=a[i],ii=i;
if (!n) return ii;
For(i,0,9) For(j,0,n) memset(dp[i][j],0,sizeof(dp[i][j]));
For(i,0,n) dp[0][i][0][i+a[0]]=c[n][i];
For(i,0,8) For(j,0,n) For(k,0,i) For(l,0,n+ma) if (dp[i][j][k][l]){
//if (n==1) cout<<i<<' '<<j<<' '<<k<<' '<<l<<' '<<dp[i][j][k][l]<<endl;
ll tmp=dp[i][j][k][l];
For(d,0,n-j){
int now=a[i+1]+d;
if (l>now) dp[i+1][d+j][k][l]=(dp[i+1][d+j][k][l]+c[n-j][d]*tmp)%mo;
else dp[i+1][d+j][i+1][d+a[i+1]]=(dp[i+1][d+j][i+1][d+a[i+1]]+c[n-j][d]*tmp)%mo;
}
}
ll ans=0;
For(k,0,9) For(l,1,n+ma){
//if (n==1) cout<<' '<<k<<' '<<l<<' '<<dp[9][n][k][l]<<endl;
ans+=dp[9][n][k][l]*k%mo;
}
return ans%mo;
}
ll ani[53];
char ch[53];
ll work(int n){
ll ans=0;
For(i,1,n){
int mi=0; if (i==1) mi=1;
int ma=ch[i]-1; if (i==n) ma=ch[i];
For(j,mi,ma){
++a[j]; ans+=cal(n-i); --a[j];
}
++a[ch[i]];
}
return ans%mo;
}
int main(){
init();
For(i,1,49){
For(j,1,9){
memset(a,0,40);
a[j]=1;
ani[i]+=cal(i-1);
//cout<<endl;
}
ani[i]%=mo;
}
/*
int ss=0;
For(i,1,6){
ss+=ani[i];
cout<<' '<<ss<<endl;
}*/
int _; cin>>_;
while(_--){
scanf("%s",ch+1);
//For(i,1,50) ch[i]='9';
int n=strlen(ch+1);
memset(a,0,40);
ll ans=0;
For(i,1,n-1) ans+=ani[i];
For(i,1,n) ch[i]-=48;
ans+=work(n);
printf("%lld\n",ans%mo);
}
cerr<<clock()<<endl;
}
/*
9
98
998
99998
999998
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 138ms
memory: 6796kb
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: 142ms
memory: 6672kb
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: 136ms
memory: 6876kb
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: 138ms
memory: 6868kb
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: 138ms
memory: 7240kb
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: 137ms
memory: 7100kb
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: 138ms
memory: 6884kb
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: 135ms
memory: 6832kb
input:
3 5014252832385738 8762796162648653 919997886706385
output:
9799428 317162349 958637285
result:
wrong answer 1st numbers differ - expected: '892033338', found: '9799428'