QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#369487 | #4904. 圆滚滚的算术占卜 | dengtingyu | 10 | 175ms | 555892kb | C++14 | 2.5kb | 2024-03-28 11:43:58 | 2024-03-28 11:43:59 |
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;}
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-ksm(10,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;add(an,x);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));
while(ti--){
ll l,r;cin>>l>>r;ll ans=0;for(int 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: 175ms
memory: 555140kb
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: 51ms
memory: 555824kb
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: 12ms
memory: 555724kb
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: 8ms
memory: 555892kb
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: 555860kb
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: 11ms
memory: 555832kb
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: 15ms
memory: 555748kb
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: 24ms
memory: 555772kb
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: 0
Time Limit Exceeded
Dependency #2:
100%
Accepted
Test #11:
score: 0
Time Limit Exceeded
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:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%