QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#39806 | #2835. Number Theory | MoQz | WA | 55ms | 14780kb | C++ | 2.6kb | 2022-07-13 20:31:18 | 2022-07-13 20:31:18 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define jx 999999999
int n;
char s[5011];
int a[5011];
int f[2][120011][3];
int mid=60001;
int zc[2][120011],len[2];
int bz[120011],g[2000011];
int Abs(int x){
if(x<0)return -x;
return x;
}
int d[2000011],er[10];
void ycl(){
fo(i,0,1)
fo(j,1,100002)
fo(k,0,2){
f[i][j][k]=jx;
}
er[0]=9;
fo(i,1,9)er[i]=er[i-1]*10+9;
fo(i,1,2000000){
g[i]=jx;
}
int h=0,t=1;
d[1]=0;
while(h<t){
int x=d[++h];
fo(i,0,5){
if(x+er[i]<=2000000&&g[x+er[i]]>(g[x]+i+1)){
g[x+er[i]]=g[x]+1+i;
d[++t]=x+er[i];
}
int r=Abs(x-er[i]);
if(g[r]>g[x]+1+i){
g[r]=g[x]+1+i;
d[++t]=r;
}
}
}
}
int main(){
// freopen("ones.in","r",stdin);
// freopen("ones.out","w",stdout);
int t=1;
// scanf("%d",&t);
ycl();
while(t){
// --t;
char c=getchar();
while(c<'0'||c>'9'){
c=getchar();
if(c==EOF)break;
}
if(c==EOF)break;
n=0;
while(c>='0'&&c<='9'){
s[n++]=c;
c=getchar();
}
// scanf("%s",s);
// n=strlen(s);
fo(i,mid-n*10,mid+n*10){
bz[i]=0;
}
fo(i,0,n-1)a[n-i]=s[i]-'0';
int u2=0;
fo(i,1,n){
u2+=a[i]*9;
a[i]=u2%10;
u2/=10;
}
while(u2){
a[++n]=u2%10;u2/=10;
}
while(n<6)++n;
int b2=(n+1)&1;
f[b2][mid][1]=0;
f[b2][mid+1][0]=n;
zc[b2][++len[b2]]=mid;
zc[b2][++len[b2]]=mid+1;
fod(i,n,6){
int u=(i&1);
int v=(u^1);
fo(j,1,len[v]){
fo(k,-1,1){
int r=zc[v][j];
if(f[v][r][k+1]!=jx&&Abs(r-mid)<=n*5){
int h=k*10+a[i];
if(bz[r+h]!=i){
bz[r+h]=i;
zc[u][++len[u]]=r+h;
}
if(bz[r+h+1]!=i){
bz[r+h+1]=i;
zc[u][++len[u]]=r+h+1;
}
if(bz[r+h-1]!=i){
bz[r+h-1]=i;
zc[u][++len[u]]=r+h-1;
}
if(f[u][r+h][1]>f[v][r][k+1]+Abs(h)*(i-1)){
f[u][r+h][1]=f[v][r][k+1]+Abs(h)*(i-1);
}
if(f[u][r+h+1][0]>f[v][r][k+1]+Abs(h+1)*(i-1)){
f[u][r+h+1][0]=f[v][r][k+1]+Abs(h+1)*(i-1);
}
if(f[u][r+h-1][2]>f[v][r][k+1]+Abs(h-1)*(i-1)){
f[u][r+h-1][2]=f[v][r][k+1]+Abs(h-1)*(i-1);
}
f[v][r][k+1]=jx;
}
}
}
len[v]=0;
}
int u=0;
fod(i,5,1){
u=u*10+a[i];
}
int ans=jx;
fo(j,1,len[0]){
int r=zc[0][j];
fo(k,-1,1){
if(f[0][r][k+1]!=jx){
ans=min(ans,f[0][r][k+1]+g[Abs(u+r-mid+k*100000)]);
}
f[0][r][k+1]=jx;
}
}
while(n){
a[n--]=0;
}
len[0]=0;
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 14724kb
input:
12 100 998244353
output:
3 5 76
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 13ms
memory: 14664kb
input:
4296 5370 8014 9532 6311 4070 2541 4782 5630 1487 2916 454 2020 5650 1851 5885 3556 6533 5044 1780 5746 5605 7860 4416 4495 8081 2416 3534 6045 3348 4536 8725 3505 1074 1531 937 7954 4451 7052 9586 3468 2679 6085 9908 3630 8046 6282 2883 9021 1436 5201 8166 8986 2167 7780 4156 101 3753 5732 5173 118...
output:
29 36 28 27 35 36 22 30 32 22 33 15 20 30 28 32 19 29 40 22 34 34 30 26 30 35 24 23 42 18 26 28 31 14 22 22 33 22 43 30 21 24 42 19 30 33 43 30 21 18 34 36 21 18 19 34 6 30 35 42 14 27 36 32 23 25 30 35 28 22 32 27 41 39 26 37 30 28 39 35 22 24 32 44 35 36 35 42 22 22 31 35 25 32 32 15 17 33 38 31 2...
result:
ok 9999 lines
Test #3:
score: 0
Accepted
time: 10ms
memory: 14756kb
input:
16528 11452 14198 11877 11309 14176 10807 19189 12063 11011 11618 18292 19862 13144 16834 16652 14120 17091 19836 16498 17655 19144 14088 13370 12709 17115 14482 10958 12306 17891 17979 10705 10036 17976 12035 18042 17495 14498 10163 15926 12209 18908 13033 19875 11699 14361 14785 14253 12647 14726 ...
output:
37 19 29 21 17 33 24 37 24 10 32 47 30 25 40 30 30 44 33 40 32 34 31 23 30 42 28 18 21 31 37 28 18 38 23 42 48 28 25 41 13 29 28 26 26 30 31 31 28 38 26 20 30 36 43 31 40 40 38 31 27 26 28 35 33 39 19 24 36 36 20 20 27 32 43 23 20 28 29 40 31 35 25 20 31 32 40 41 40 41 33 39 39 42 37 12 21 10 30 39 ...
result:
ok 10000 lines
Test #4:
score: 0
Accepted
time: 8ms
memory: 14712kb
input:
25172 29204 28892 23128 21312 28850 23340 27350 21632 29705 29655 24700 27992 23570 28822 21683 26260 26497 28092 22514 28528 23098 26446 27220 22261 28727 28177 23884 28830 24460 26841 29986 23893 28374 24608 22374 22731 26925 22753 24241 20202 24668 23072 21788 27823 23938 23414 22339 20247 20546 ...
output:
45 48 34 28 25 43 20 50 33 47 39 31 42 26 42 32 49 42 47 30 50 24 34 42 22 48 50 33 45 25 43 32 34 55 33 24 35 42 31 31 30 26 32 25 40 43 26 19 31 32 36 42 50 35 51 36 39 22 27 34 47 48 42 40 46 31 37 43 29 37 49 48 33 26 13 40 46 43 34 40 38 47 35 30 24 26 33 49 27 46 29 28 46 33 34 37 53 42 42 42 ...
result:
ok 10000 lines
Test #5:
score: 0
Accepted
time: 17ms
memory: 14664kb
input:
35458 30814 33590 33177 30718 35952 39315 37797 38544 32595 34013 36806 38978 37445 32117 35080 36177 36811 38996 33557 35833 36013 31989 33626 30095 30732 32497 32972 39513 35802 38572 36304 37335 39638 30390 30443 30181 37677 30341 33589 34504 37365 38395 38755 32061 37743 36823 34880 31171 38806 ...
output:
31 41 29 27 47 46 55 37 46 40 35 40 43 41 28 43 48 37 41 23 40 40 27 36 37 42 37 34 57 36 52 46 45 55 48 40 44 36 41 28 34 50 60 42 36 38 40 36 38 48 32 46 37 49 33 35 48 34 41 41 32 37 49 29 32 40 53 48 42 26 30 40 35 37 30 43 56 32 37 32 32 24 33 39 48 37 39 35 46 52 53 57 35 24 33 40 34 45 53 33 ...
result:
ok 10000 lines
Test #6:
score: 0
Accepted
time: 15ms
memory: 14600kb
input:
47583 45587 40557 41413 48126 43227 41361 49755 42400 48511 46835 42685 42425 44853 41732 45421 44157 41929 47256 42185 49905 47237 45004 40732 41670 44069 40082 42147 49510 40690 45655 41481 48052 40609 43269 48612 46900 46706 40691 48979 49898 46602 43411 47434 42544 40816 49880 40217 45017 47779 ...
output:
48 31 48 49 48 32 48 50 42 53 44 47 41 40 50 32 39 49 51 38 51 50 40 51 46 39 49 40 61 49 29 51 50 57 38 53 37 40 50 45 46 42 33 44 39 52 48 47 43 34 45 32 42 43 38 41 44 53 31 48 51 45 41 55 29 41 42 36 42 47 38 54 37 35 40 34 45 45 35 42 41 42 33 37 44 56 41 54 29 50 37 51 47 50 39 47 40 39 55 40 ...
result:
ok 10000 lines
Test #7:
score: 0
Accepted
time: 14ms
memory: 14604kb
input:
55562 56846 58105 54937 52692 50178 54319 54915 50557 52656 56355 57363 54038 52812 53176 59197 57326 59159 59531 57845 56859 57711 55867 50764 56134 52439 55360 52162 57155 52264 53214 59034 55078 59088 57901 56623 55475 56947 56875 59270 57531 56644 55171 54900 53866 59246 55120 50452 57034 58555 ...
output:
31 45 47 54 57 55 37 50 57 52 42 54 52 55 46 52 51 56 59 45 45 45 39 55 46 48 40 52 50 47 41 48 43 47 40 38 36 49 39 59 45 33 48 44 49 53 41 56 46 46 46 53 49 44 46 45 40 45 62 40 55 56 50 45 40 47 44 52 49 59 49 50 53 41 32 43 54 47 50 44 44 43 49 40 52 55 42 31 41 55 49 42 54 41 58 45 53 46 50 51 ...
result:
ok 10000 lines
Test #8:
score: 0
Accepted
time: 12ms
memory: 14780kb
input:
68733 60810 67393 64496 65059 60979 63486 67951 63442 63390 62976 67541 63288 61770 63615 62708 63675 64462 60143 67574 65757 62877 69434 60667 68109 65801 61749 60594 62448 61977 60014 69238 63419 63440 60449 64529 65693 65650 69566 62932 64440 64388 62977 67095 69177 65421 67034 63159 67234 64999 ...
output:
46 60 52 48 54 53 52 49 44 49 54 42 48 58 58 65 52 42 50 44 41 54 52 58 41 41 63 68 51 54 47 50 49 46 59 46 41 41 53 60 39 46 53 45 52 39 42 55 44 47 47 44 51 54 40 61 41 48 41 52 49 50 42 41 35 54 49 42 48 54 56 42 63 43 50 41 51 58 57 57 43 41 54 59 63 66 56 45 43 63 65 41 43 38 57 54 47 43 46 51 ...
result:
ok 10000 lines
Test #9:
score: 0
Accepted
time: 10ms
memory: 14756kb
input:
70451 77409 73192 73579 75086 78154 78238 75957 78550 75617 78564 73870 74725 70590 73332 74045 70687 76389 79692 74760 73538 74386 77646 76853 75878 79897 76404 71876 76587 73889 76008 73574 77829 72673 76321 74783 75211 70235 70292 74476 74216 71549 78231 77353 79686 71120 71752 78548 77730 70493 ...
output:
56 39 48 48 49 39 40 50 40 45 39 54 52 61 39 53 60 42 45 50 51 47 29 40 40 37 42 55 36 49 46 51 35 59 38 47 41 48 58 41 45 60 37 40 45 46 62 39 33 63 48 30 53 47 42 44 44 49 47 48 41 57 50 40 63 45 48 44 47 54 51 51 48 43 59 49 33 42 46 39 53 42 32 38 44 43 64 50 56 46 56 41 46 33 48 34 57 42 58 53 ...
result:
ok 10000 lines
Test #10:
score: 0
Accepted
time: 9ms
memory: 14704kb
input:
86492 82042 82395 85456 82379 83405 84464 80074 82438 88208 81516 82815 87181 88276 81288 89085 80748 82539 84837 88160 85818 83695 89219 89825 81747 88241 84428 87307 83517 81371 80557 89236 80342 83252 82503 89808 86584 82599 80539 86491 84521 81155 86352 80720 86012 87141 86667 83075 80697 80963 ...
output:
41 53 56 33 50 51 39 42 49 37 57 60 45 43 48 30 51 53 55 42 46 55 28 37 57 39 40 41 54 50 46 30 42 49 57 35 37 54 51 40 43 41 41 55 43 45 24 52 54 46 32 42 44 34 46 36 43 53 44 27 42 47 45 52 41 39 61 57 35 25 52 43 38 50 41 54 37 47 26 44 35 30 39 28 49 42 49 26 51 28 53 35 45 43 37 44 52 53 54 32 ...
result:
ok 10000 lines
Test #11:
score: 0
Accepted
time: 16ms
memory: 14720kb
input:
98444 95686 99650 91810 92829 90145 94267 90093 95597 92642 94279 97359 91044 99840 92439 97572 99845 92132 92676 96111 91222 97743 96688 99396 95545 95983 98381 98418 92309 92481 98112 92293 94426 90088 99648 92689 93574 96073 94906 98190 97349 91640 98879 92966 94198 94040 98573 98144 91707 93616 ...
output:
28 37 28 47 56 30 45 31 38 46 44 38 35 27 39 32 22 36 43 39 27 27 28 39 29 47 41 36 37 44 29 43 38 28 27 45 45 50 51 38 37 47 18 48 44 55 32 34 50 54 30 30 51 41 45 32 47 32 41 19 49 46 42 30 27 54 37 37 33 43 29 36 48 35 52 47 28 28 29 30 38 46 45 34 35 45 41 45 41 51 45 38 40 51 23 27 35 34 54 51 ...
result:
ok 10000 lines
Test #12:
score: -100
Wrong Answer
time: 55ms
memory: 14660kb
input:
99647655441310714404533248973861508920 2073756854781 97786932 697203586561561 220 92603944 857 4913 37162832688008526170899875515887671731826673 1480102698509 402012655841707502050341636832 75136137088485508854715245558132922867818030309 4114635151757 770 75 82646730706547052 496224488355898625 2477...
output:
1421 213 59 356 8 122 17 35 2244 194 1267 2802 247 18 12 460 440 1402 13 243 108 2410 111 2054 119 3722 58 2381 785 2822 65 26 1443 1931 57 153 382 64 247 876 2850 78 1344 518 390 889 1323 215 690 2538 1352 1640 1775 1963 108 655 8 1539 1647 57 522 44 1798 1800 1369 22 583 11 585 138 1325 544 3044 1...
result:
wrong answer 9th lines differ - expected: '2713', found: '2244'