ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#164559 | #2909. number | LZDQ | 100 | 2384ms | 956kb | C++ | 1.4kb | 2022-11-04 12:07:25 | 2022-11-04 12:07:26 |
answer
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
typedef long long ll;
ll pw[10],f[10][100][100];
int Cnt(ll x){
int s=0;
while(x)
s+=x%10,x/=10;
return s;
}
int main(){
//freopen("number.in","r",stdin);
//freopen("number.out","w",stdout);
pw[0]=1;
for(int i=1; i<10; i++)
pw[i]=pw[i-1]*10;
for(int j=0; j<100; j++){
f[0][j][0]=j;
for(int k(j?0:1); k<10; k++){
ll x=k;
while(x<10)
x+=Cnt(x)+j;
f[1][j][k]=x-k;
}
}
for(int i=2; i<10; i++)
for(int j=0; j<=9*(10-i); j++)
for(int k(j?0:1); k<100; k++){
ll x=k;
for(int l=i-1; ~l; l--)
while(x/pw[l]%10<9){
assert(j+Cnt(x/pw[l])<100);
assert(x%pw[l]<100);
ll _x=x+f[l][j+Cnt(x/pw[l])][x%pw[l]];
if(_x<pw[i]) x=_x;
else break;
}
x+=Cnt(x)+j;
assert(x>=pw[i]);
f[i][j][k]=x-k;
}
//return 0;
int _; scanf("%d",&_);
while(_--){
ll x,y;
scanf("%lld%lld",&x,&y);
int l=2;
while(l<10){
assert(x%pw[l]<100);
ll _x=x+f[l][Cnt(x/pw[l])][x%pw[l]];
if(_x>y) break;
x=_x;
while(x/pw[l]%10){
assert(x%pw[l]<100);
_x=x+f[l][Cnt(x/pw[l])][x%pw[l]];
if(_x>y) break;
x=_x;
}
if(_x>y) break;
l++;
}
while(l--)
while(1){
assert(x%pw[l]<100);
ll _x=x+f[l][Cnt(x/pw[l])][x%pw[l]];
if(_x>y) break;
x=_x;
}
x+=Cnt(x);
printf("%lld\n",x);
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 322ms
memory: 956kb
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: 743ms
memory: 956kb
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: 435ms
memory: 956kb
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: 31ms
memory: 952kb
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: 853ms
memory: 952kb
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