ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#165414 | #2909. number | noibs | 100 | 2421ms | 1996kb | C++ | 1.5kb | 2022-11-11 11:08:43 | 2022-11-11 11:08:45 |
answer
#include<bits/stdc++.h>
using namespace std;
long long f[10][91][90],p10[11];
int cnt[100000];
inline int getcnt(long long x){return cnt[x/100000]+cnt[x%100000];}
void init(){
int i,j,k;
p10[0]=1;
for(i=1;i<=10;++i) p10[i]=p10[i-1]*10;
for(i=1;i<100000;++i) cnt[i]=i%10+cnt[i/10];
for(i=1;i<10;++i){
for(j=0;j<=9*(10-i);++j){
for(k=0;k<=89;++k){
if(j==0&&k==0) continue;
if(k>=p10[i]) break;
long long tmp=k;
while(1){
int o=tmp/p10[i-1];
tmp+=f[i-1][j+o][tmp-o*p10[i-1]];
o=getcnt(tmp)+j;
if(tmp+o<p10[i]) tmp+=o;
else break;
}
f[i][j][k]=tmp-k;
}
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
init();
int q;
cin>>q;
int ii;
for(ii=1;ii<=q;++ii){
long long x,y;
cin>>x>>y;
int i;
bool flag=0;
for(i=0;i<10;++i){
long long tmp=x%p10[i];
int b=x/p10[i]%10,tcnt=getcnt(x-tmp-b*p10[i]);
while(1){
long long o=f[i][tcnt+b][tmp];
if(x+o>y){
flag=1;
break;
}
long long tx=x+o;
tmp+=o;
o=tcnt+b+getcnt(tmp);
if(tx+o>y){
flag=1;
break;
}
x=tx+o;
tmp+=o+b*p10[i];
if(tmp>=p10[i+1]) break;
b=tmp/p10[i];
tmp-=b*p10[i];
}
if(flag) break;
}
for(--i;i>=0;--i){
while(1){
long long tmp=x%p10[i];
int tcnt=getcnt(x-tmp);
long long o=f[i][tcnt][tmp];
if(x+o>y) break;
long long tx=x+o;
o=getcnt(tx);
if(tx+o>y) break;
x=tx+o;
}
}
if(x<=y) x+=getcnt(x);
cout<<x<<'\n';
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 374ms
memory: 1996kb
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: 817ms
memory: 1996kb
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: 452ms
memory: 1992kb
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: 5ms
memory: 1988kb
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: 773ms
memory: 1992kb
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