QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#369489 | #4904. 圆滚滚的算术占卜 | dengtingyu | 30 | 276ms | 564692kb | C++14 | 2.6kb | 2024-03-28 11:49:19 | 2024-03-28 11:49:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define yu (998244353)
inline ll ksm(ll x,ll y=yu-2){
ll an=1;for(;y;y>>=1){
if(y&1)an=an*x%yu;
x=x*x%yu;
}return an;
}
inline void add(ll &x,ll y){x+=y;if(x>=yu)x-=yu;return ;}
#define N 21
#define B 11
struct node{
ll x,y;
node(ll a=0,ll b=0){x=a;y=b;return ;}
}g[N][N][N*B][B][N];
ll rc[N][N][N*B][B][N],gs[N][N][N*B][B][N];
node operator+(node x,node y){add(x.x,y.x);add(x.y,y.y);return x;}
node operator*(node x,ll y){return node(x.x*y%yu,x.y*y%yu);}
inline ll gt(node x,ll y){return x.x*y+x.y;}
inline ll hs(ll x){ll g=0;while(x)g++,x/=10;return g;}
inline ll sum(ll x){ll s=0;while(x)s+=x%10,x/=10;return s;}
ll pw[N];
inline void solve(ll k,ll l,ll s,ll u,ll y){
if(rc[k][l][s][u][y/9]!=-1)return ;
ll &o=rc[k][l][s][u][y/9],&p=gs[k][l][s][u][y/9];node &q=g[k][l][s][u][y/9];o=0;
if(k==3){
ll tem=u*1000+1000-y;
if(l<=1){
while(tem>0){
ll tt=sum(tem);q=(q*ksm(10,hs(tem))+node(ksm(10,k),tem));
o+=tt;p+=hs(tem);tem-=tt;
}return ;
}while(tem>=0){
ll tt=sum(tem)+s;q=(q*ksm(10,l+k)+node(ksm(10,k),tem));
o+=tt;p+=l+k;tem-=tt;
}return ;
}solve(k-1,l+1,s+u,9,y);
ll e=rc[k-1][l+1][s+u][9][y/9],t=gs[k-1][l+1][s+u][9][y/9];node c=g[k-1][l+1][s+u][9][y/9];
o=e;p=t;q.x=c.x*10%yu;q.y=(c.y+u*10*c.x)%yu;
if(!u)return ;
ll ny=e+y-pw[k];
if(u-1==0&&l==1)l--;
solve(k,l,s,u-1,ny);
o+=rc[k][l][s][u-1][ny/9];p+=gs[k][l][s][u-1][ny/9];q=(q*ksm(10,gs[k][l][s][u-1][ny/9])+g[k][l][s][u-1][ny/9]);
return ;
}
ll an=0;
inline void gt(ll &x){
ll s=0,g=0,nw=x;while(nw){
g++;s+=nw%10;nw/=10;
}an=an*ksm(10,g)%yu;an=(an+x)%yu;x-=s;return ;
}
inline ll suan(ll x){
an=0;while(x>0&&(x%9!=0||(x%1000)<1000-18*9))gt(x);
ll k=3,bas=1000,n=x,y=bas-x%bas;x=(x/bas);while(n){
solve(k,hs(x),sum(x)-x%10,x%10,y);
n-=rc[k][hs(x)][sum(x)-x%10][x%10][y/9];
an=(an*ksm(10,gs[k][hs(x)][sum(x)-x%10][x%10][y/9])+gt(g[k][hs(x)][sum(x)-x%10][x%10][y/9],x-x%10))%yu;
k++;bas=bas*10;x=n/bas;y=bas-n%bas;
}return an;
}
int main(){
// freopen("test1.in","r",stdin);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll ti;cin>>ti;memset(rc,-1,sizeof(rc));pw[0]=1;for(int i=1;i<=18;i++)pw[i]=pw[i-1]*10;
while(ti--){
ll l,r;cin>>l>>r;ll ans=0;for(ll i=l;i<=r;i++)add(ans,suan(i));
cout<<ans<<'\n';
}return 0;
}
詳細信息
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 5
Accepted
time: 184ms
memory: 555176kb
input:
10 9653 62002 91160 95589 4602 60141 54240 79592 69170 95623 46733 68190 25361 84435 23506 99583 62553 65996 22099 81703
output:
103592019 222392703 236171250 287406393 478554731 117904238 522507555 617451444 277292124 553293749
result:
ok 10 numbers
Test #2:
score: -5
Time Limit Exceeded
input:
500 174 85257 53439 99201 25556 99022 59548 92909 61936 77935 35851 62882 67138 71164 42431 65794 15439 89519 5723 18456 23983 25568 22597 68086 23328 93569 9292 67330 18318 88994 84792 90364 13981 83990 21502 61839 4123 63779 498 68986 34607 65882 11483 67457 22349 94822 24528 42149 14737 16569 643...
output:
result:
Subtask #2:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 49ms
memory: 555728kb
input:
5 14151615 14151615 50959220 50959220 177962208 177962208 173507309 173507309 608527742 608527742
output:
574888399 728657674 419976531 502012045 456375259
result:
ok 5 number(s): "574888399 728657674 419976531 502012045 456375259"
Test #5:
score: 0
Accepted
time: 32ms
memory: 555716kb
input:
5 441384319 441384319 606726578 606726578 100872719 100872719 290542038 290542038 290435521 290435521
output:
304014472 49910017 871510667 927387471 830052470
result:
ok 5 number(s): "304014472 49910017 871510667 927387471 830052470"
Test #6:
score: 0
Accepted
time: 27ms
memory: 555732kb
input:
5 686934834 686934834 217972715 217972715 91760217 91760217 478910665 478910665 871116356 871116356
output:
95543981 675033334 382398698 617891543 7219851
result:
ok 5 number(s): "95543981 675033334 382398698 617891543 7219851"
Test #7:
score: 0
Accepted
time: 23ms
memory: 555792kb
input:
5 632445684 632445684 734428390 734428390 713862928 713862928 749060122 749060122 542269196 542269196
output:
651099756 192673041 504124590 272521896 299385724
result:
ok 5 number(s): "651099756 192673041 504124590 272521896 299385724"
Test #8:
score: 0
Accepted
time: 20ms
memory: 555828kb
input:
5 292694554 292694554 122280051 122280051 174892392 174892392 9910543 9910543 784522094 784522094
output:
419465926 714229591 283421374 481713044 109145296
result:
ok 5 number(s): "419465926 714229591 283421374 481713044 109145296"
Test #9:
score: 0
Accepted
time: 23ms
memory: 555736kb
input:
5 615497298 615497298 564113448 564113448 753391603 753391603 551814992 551814992 174017428 174017428
output:
22576684 137456470 513923958 668473835 317575304
result:
ok 5 number(s): "22576684 137456470 513923958 668473835 317575304"
Test #10:
score: 0
Accepted
time: 28ms
memory: 555856kb
input:
5 1000000000 1000000000 999999999 999999999 999999998 999999998 999999997 999999997 999999996 999999996
output:
222450657 694100606 163329444 630802635 100031473
result:
ok 5 number(s): "222450657 694100606 163329444 630802635 100031473"
Subtask #3:
score: 20
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 20
Accepted
time: 27ms
memory: 557312kb
input:
500 698257830800 698257830800 617173242289 617173242289 568533976816 568533976816 304124481699 304124481699 382703992871 382703992871 369767377948 369767377948 486827431792 486827431792 816809127260 816809127260 140820315808 140820315808 520319250284 520319250284 846471367899 846471367899 6644006698...
output:
222330930 123963642 587561052 308401894 682034676 921899282 635390969 240575157 625354160 786668808 221490848 108019577 890900322 968212472 748737678 399442868 722933325 949500244 544379125 537942485 770467247 611295351 124083002 187265170 716761105 332601799 604625136 426579833 173698309 380930698 ...
result:
ok 500 numbers
Test #12:
score: 0
Accepted
time: 35ms
memory: 557300kb
input:
500 421409955150 421409955150 288525860973 288525860973 654212997028 654212997028 643994843193 643994843193 234986303016 234986303016 883443909286 883443909286 191709557117 191709557117 853488646551 853488646551 830288496202 830288496202 912705252384 912705252384 385442976112 385442976112 9404880703...
output:
213055714 157010848 237776173 970746980 979282626 886191091 915071656 204965025 396181281 552769762 88640338 284657564 927286525 675552858 992967824 352706406 566507446 920489107 338095947 561665777 861701687 201836223 281362047 485972857 762735669 689735145 329154384 98340611 518700765 238302555 75...
result:
ok 500 numbers
Test #13:
score: 0
Accepted
time: 44ms
memory: 557296kb
input:
500 898187490904 898187490904 523028464608 523028464608 551979765943 551979765943 446016706274 446016706274 882533125415 882533125415 973648759862 973648759862 243336600342 243336600342 540842065913 540842065913 754331041749 754331041749 205670838484 205670838484 904025050365 904025050365 1915561766...
output:
343687254 731317462 273353940 56914574 420502214 931444452 27403305 268858558 73111834 765813040 988209771 377981743 693681456 995761977 507100649 127678626 570683366 942992120 396722742 719060747 768923853 975693001 589720135 198036309 996310965 811266887 709380198 516505552 451083136 745217370 553...
result:
ok 500 numbers
Subtask #4:
score: 0
Wrong Answer
Dependency #3:
100%
Accepted
Test #14:
score: 0
Wrong Answer
time: 276ms
memory: 564692kb
input:
50000 243477608435765905 243477608435765905 618229616631065936 618229616631065936 340655097845225107 340655097845225107 164063479621476366 164063479621476366 211153058113364687 211153058113364687 534183445145939234 534183445145939234 968971748161242908 968971748161242908 971741312228667011 971741312...
output:
826908805 309021062 367032066 57146822 476805108 423510644 295435502 326114583 174556818 758243839 848157712 218169754 768826092 87693195 365666111 205491117 688940041 623136903 299292406 713836581 212592315 832638394 417786627 29680862 158635988 108230494 -710618606 604489190 361389659 309498295 25...
result:
wrong answer 1st numbers differ - expected: '120004358', found: '826908805'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%