QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#369490 | #4904. 圆滚滚的算术占卜 | dengtingyu | 60 | 278ms | 564804kb | C++14 | 2.6kb | 2024-03-28 11:51:23 | 2024-03-28 11:51:25 |
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 (y%yu*x.x+x.y)%yu;}
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: 192ms
memory: 555192kb
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: 28ms
memory: 555812kb
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: 31ms
memory: 555868kb
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: 555788kb
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: 24ms
memory: 555788kb
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: 12ms
memory: 555792kb
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: 31ms
memory: 555724kb
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: 4ms
memory: 555852kb
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: 36ms
memory: 557340kb
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: 32ms
memory: 557260kb
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: 27ms
memory: 557304kb
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: 30
Accepted
Dependency #3:
100%
Accepted
Test #14:
score: 30
Accepted
time: 258ms
memory: 564804kb
input:
50000 243477608435765905 243477608435765905 618229616631065936 618229616631065936 340655097845225107 340655097845225107 164063479621476366 164063479621476366 211153058113364687 211153058113364687 534183445145939234 534183445145939234 968971748161242908 968971748161242908 971741312228667011 971741312...
output:
120004358 629474440 155342766 244130769 246410395 687860060 93807056 619446109 432788371 87496004 677988327 813378356 745700608 218030110 300354433 786382437 757604339 423161582 607094440 561223491 306602758 72559127 513724638 277976752 891665800 273777901 900791247 554544036 414227457 463705979 225...
result:
ok 50000 numbers
Test #15:
score: 0
Accepted
time: 278ms
memory: 564776kb
input:
50000 226216064999007957 226216064999007957 725876901556754918 725876901556754918 6991128333733965 6991128333733965 118226612740827945 118226612740827945 499568128994719893 499568128994719893 263555151284895991 263555151284895991 83574173851557923 83574173851557923 458819833592503898 458819833592503...
output:
706469547 351472849 828132588 408536547 129726088 990990261 237978314 969172645 355533983 881248280 278317959 83431317 132188345 769916092 466918747 170195273 897712540 363946942 589231085 623079062 771924871 780768814 445367030 841114380 618903049 704203360 633756584 512799874 51997270 206295934 66...
result:
ok 50000 numbers
Test #16:
score: 0
Accepted
time: 260ms
memory: 564732kb
input:
50000 214366518885303579 214366518885303579 701499096305610395 701499096305610395 158143163539796259 158143163539796259 744212773625008552 744212773625008552 114473183293762466 114473183293762466 958067267253912227 958067267253912227 897888722603840615 897888722603840615 331740504045801469 331740504...
output:
324286333 658948700 755495023 899388585 66603017 505069427 946221163 981059736 241787325 440845177 820409144 579209528 179849224 623939134 682188932 39277483 251059921 507626107 412330406 413820293 934035838 34621595 330624408 895172862 694999904 961324349 80495288 875778694 783146679 890651966 5377...
result:
ok 50000 numbers
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%