ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#164777 | #2909. number | 18Michael | 100 | 2295ms | 1828kb | C++11 | 922b | 2022-11-05 20:04:49 | 2022-11-05 20:04:50 |
answer
#include<bits/stdc++.h>
#define Mx 100000
#define LL long long
using namespace std;
int q,z;
int sum[Mx];
LL pw[10];
int f[10][100][100];
inline int get(LL x)
{
return sum[x%Mx]+sum[x/Mx];
}
inline void init()
{
for(int i=1;i<Mx;++i)sum[i]=sum[i/10]+i%10;
for(int i=pw[0]=1;i<10;++i)pw[i]=pw[i-1]*10;
for(int i=0;i<10;++i)for(int j=0;j<(10-i)*10;++j)for(int k=0;k<100;++k)
{
if(!i)f[i][j][k]=j;
else if(j || k)
{
for(f[i][j][k]=k;f[i][j][k]<pw[i];)f[i][j][k]+=f[i-1][j+f[i][j][k]/pw[i-1]][f[i][j][k]%pw[i-1]];
f[i][j][k]-=k;
}
}
}
int main()
{
init(),scanf("%d",&q);
for(LL x,y;q--;printf("%lld\n",x+get(x)))
{
for(scanf("%lld%lld",&x,&y);x<100 && x+(z=get(x))<=y;)x+=z;
for(int i=2;i<10;++i)for(;(x/pw[i])%10 && x+(z=f[i][get(x/pw[i])][x%100])<=y;)x+=z;
for(int i=9;~i;--i)for(;x>=pw[i] && x+(z=f[i][get(x/pw[i])][x%pw[min(2,i)]])<=y;)x+=z;
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 343ms
memory: 1828kb
input:
500000 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 ...
output:
2 4 4 8 8 8 8 16 16 16 16 16 16 16 16 23 23 23 23 23 23 23 28 28 28 28 28 38 38 38 38 38 38 38 38 38...
result:
ok 500000 lines
Test #2:
score: 0
Accepted
time: 726ms
memory: 1828kb
input:
500000 92 99927 119 99453 481 99268 29 99908 267 99547 835 99500 955 99099 734 99774 306 99883 729 9...
output:
99941 99454 99274 99941 99555 99520 99112 99775 99900 99657 99978 100010 99545 99245 99775 99907 997...
result:
ok 500000 lines
Subtask #2:
score: 25
Accepted
Test #3:
score: 25
Accepted
time: 444ms
memory: 1828kb
input:
500000 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 ...
output:
2 4 4 8 8 8 8 16 16 16 16 16 16 16 16 23 23 23 23 23 23 23 28 28 28 28 28 38 38 38 38 38 38 38 38 38...
result:
ok 500000 lines
Subtask #3:
score: 25
Accepted
Test #4:
score: 25
Accepted
time: 6ms
memory: 1828kb
input:
50 4587480273 4587480273 428862505 500400481 6920415626 7358620174 7787875953 7787884613 4542304779 ...
output:
4587480321 500400482 7358620210 7787884620 4542307848 4676070172 909798356 3555627285 9508855574 511...
result:
ok 50 lines
Subtask #4:
score: 30
Accepted
Test #5:
score: 30
Accepted
time: 776ms
memory: 1828kb
input:
500000 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 ...
output:
2 4 4 8 8 8 8 16 16 16 16 16 16 16 16 23 23 23 23 23 23 23 28 28 28 28 28 38 38 38 38 38 38 38 38 38...
result:
ok 500000 lines