QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#650484 | #2098. Distance | test123 | 100 ✓ | 231ms | 82808kb | C++14 | 1.7kb | 2024-10-18 15:21:07 | 2024-10-18 15:21:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=1000005;
const int maxm=6000005;
const int INF=0x3f3f3f3f;
int read(){
int ret=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
while( isdigit(ch)){ret=(ret<<3)+(ret<<1)+(ch&15);ch=getchar();}
return ret*f;
}
int n,N=1000000,cnt,tot;
bool is_prime[maxn],vis[maxn];
int lnk[maxn],son[maxm],nxt[maxm],prime[maxn],a[maxn],que[maxn];
struct node{
int dep,fr;
node(){dep=INF;fr=0;}
node(int d,int f){dep=d;fr=f;}
node operator+(const int l)const{return (node){dep+l,fr};}
bool operator<(const node &B)const{return (dep<B.dep)||(dep==B.dep&&fr<B.fr);}
}dis[maxn],ans[maxn];
void update(node &A,node B){
ans[A.fr]=min(ans[A.fr],(node){A.dep+B.dep,B.fr});
ans[B.fr]=min(ans[B.fr],(node){A.dep+B.dep,A.fr});
A=min(A,B);
}
void add_e(int x,int y){son[++cnt]=y;nxt[cnt]=lnk[x];lnk[x]=cnt;}
void sieve(){
for(int i=2;i<=N;++i){
if(!is_prime[i]){
prime[++tot]=i;
}
for(int j=1;j<=tot&&i*prime[j]<=N;++j){
is_prime[i*prime[j]]=1;
if(i%prime[j]==0) break;
}
}
}
void BFS(){
int hed=0,til=0;
for(int i=1;i<=n;++i){
if(!vis[a[i]]){
que[++til]=a[i];
vis[a[i]]=1;
}
}
while(hed<til){
int now=que[++hed];
for(int j=lnk[now];j;j=nxt[j]){
if(dis[son[j]].fr==dis[now].fr) continue;
update(dis[son[j]],dis[now]+1);
if(!vis[son[j]]){
vis[son[j]]=1;
que[++til]=son[j];
}
}
}
}
int main(){
sieve();
for(int i=1;i<=N;++i){
for(int j=1;j<=tot&&i*prime[j]<=N;++j){
add_e(i,i*prime[j]);
add_e(i*prime[j],i);
}
}
n=read();
for(int i=1;i<=n;++i){
a[i]=read();
update(dis[a[i]],(node){0,i});
}
BFS();
for(int i=1;i<=n;++i) printf("%d\n",ans[i].fr);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 102ms
memory: 78596kb
input:
50 93 77 24 72 23 30 90 1 75 64 60 58 33 55 74 84 68 41 88 30 35 29 15 13 60 9 32 62 86 6 48 66 7 78 87 94 41 83 71 95 36 83 47 10 76 5 57 35 40 12
output:
8 33 4 3 8 20 6 5 23 27 25 22 32 46 8 50 45 37 3 6 48 8 6 8 11 1 10 1 8 6 3 13 2 30 22 43 18 42 8 46 4 38 8 6 17 8 1 21 3 3
result:
ok 50 lines
Test #2:
score: 10
Accepted
time: 88ms
memory: 79316kb
input:
2 1 1
output:
2 1
result:
ok 2 lines
Subtask #2:
score: 10
Accepted
Test #3:
score: 10
Accepted
time: 137ms
memory: 78708kb
input:
345 287 573 173 494 86 113 39 218 586 269 322 177 230 659 95 266 489 38 101 491 302 281 554 677 505 583 11 299 431 473 443 37 373 465 365 677 269 359 3 521 661 47 13 431 479 349 670 517 607 53 347 193 619 199 599 193 61 361 282 181 211 631 381 457 241 31 646 167 659 661 565 139 21 401 197 283 157 29...
output:
168 39 174 18 93 143 39 229 325 37 121 39 158 69 214 18 39 4 254 3 123 3 119 36 19 27 26 43 44 27 194 85 3 230 316 24 10 295 2 3 70 207 7 29 3 141 263 27 287 84 195 56 3 308 138 52 124 15 98 189 112 342 39 163 3 237 18 3 14 41 6 330 39 92 79 101 97 108 39 66 263 182 32 50 32 183 209 165 3 257 99 74 ...
result:
ok 345 lines
Test #4:
score: 10
Accepted
time: 85ms
memory: 78796kb
input:
2 1 10
output:
2 1
result:
ok 2 lines
Subtask #3:
score: 10
Accepted
Test #5:
score: 10
Accepted
time: 112ms
memory: 82808kb
input:
584 2269 1097 2749 1321 487 1021 2659 1549 397 2137 661 1951 840 1721 761 89 641 1069 503 1447 1913 2333 2573 2719 2083 643 1640 1109 3469 2729 2377 251 313 3083 2687 673 457 612 937 2179 1381 2143 241 1297 2464 1730 2953 2971 3121 791 223 1579 2243 1181 2069 3049 3433 1433 587 1787 941 1277 479 957...
output:
2 1 1 1 1 1 1 1 1 1 1 1 328 1 1 1 1 1 1 1 1 1 510 1 1 1 378 1 1 1 1 1 1 1 1 1 1 260 1 1 1 1 1 1 503 439 1 1 1 274 1 1 1 1 1 1 1 1 1 1 1 1 1 228 1 1 418 1 1 1 1 1 1 1 1 1 1 1 1 1 1 458 1 1 1 515 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 158 308 1 1 1 1 1 46 1 1 1 1 1 1 1 1 45 1 291 1 1 1 1 1 1 1 1 1 1 1 67 1 ...
result:
ok 584 lines
Test #6:
score: 10
Accepted
time: 141ms
memory: 79360kb
input:
1000 498 310 2895 2722 40 1467 3098 1602 954 1730 1498 750 108 3327 73 354 2993 1144 1549 1008 1528 3367 2652 1927 2849 2091 882 377 1356 2229 3248 371 2467 2061 943 294 904 1400 2146 2562 2063 3111 2651 1845 2948 1013 2237 2680 1123 123 362 3255 2935 3163 1769 203 770 1098 453 3342 3500 1172 3051 7...
output:
16 563 935 730 48 243 19 119 117 673 816 383 106 894 17 1 15 311 7 370 267 180 943 724 22 50 36 55 69 64 167 187 94 380 147 27 69 674 153 36 94 150 779 174 1000 94 94 5 94 26 466 799 608 94 28 162 223 646 610 1 636 75 78 30 730 761 896 5 29 94 380 122 91 730 638 894 264 44 94 136 719 894 94 668 763 ...
result:
ok 1000 lines
Test #7:
score: 10
Accepted
time: 93ms
memory: 78716kb
input:
10 10 6 9 7 2 1 5 4 3 8
output:
5 5 9 6 1 4 1 5 2 8
result:
ok 10 lines
Subtask #4:
score: 10
Accepted
Test #8:
score: 10
Accepted
time: 130ms
memory: 78848kb
input:
11884 21951 47436 40222 53742 24390 43500 63128 40710 51350 77308 38097 55760 65538 9594 80541 15384 17982 48264 38760 77336 20670 13455 16016 63272 50040 30969 79434 24894 67596 29436 74061 38610 78921 18444 67527 18634 67880 75999 60138 52245 43602 69993 17120 28830 37632 65348 75152 3696 74740 41...
output:
138 813 172 21 135 281 76 94 258 75 257 204 397 39 319 18 347 16 494 136 4 161 47 148 72 33 28 27 462 129 235 59 26 87 729 866 58 104 14 84 4 205 89 690 763 825 23 23 277 57 570 238 74 224 16 27 50 37 32 133 78 164 183 1946 159 423 196 1879 286 426 50 25 16 53 10 7 111 61 214 287 494 826 185 40 61 1...
result:
ok 11884 lines
Test #9:
score: 10
Accepted
time: 174ms
memory: 79720kb
input:
21234 40142 20991 12713 34476 5122 22129 7599 32688 2711 18449 836 24864 42753 44407 249 37634 13191 40706 44944 5222 21078 11739 16034 16537 1541 27244 1042 40802 13544 36647 2794 44005 25977 10383 30093 4841 41292 12621 16673 35367 9422 5446 9097 26553 7188 2221 28956 26351 31786 14614 27908 2146 ...
output:
1002 13 5545 2967 7917 3 2531 527 334 17540 3505 2143 2 4282 2900 323 10573 1 18973 13614 16932 6581 1 13267 5275 18680 3799 5117 11957 4805 4905 10923 13790 10087 2988 1835 5150 876 3 2 4149 20 11646 13064 5984 360 4278 4805 4249 20856 102 870 9037 5861 3010 646 4935 17697 8066 3 726 8265 12614 115...
result:
ok 21234 lines
Test #10:
score: 10
Accepted
time: 86ms
memory: 78652kb
input:
19 512 65536 128 8192 262144 16384 131072 1 4096 2048 8 256 2 1024 32 32768 64 4 16
output:
12 7 12 6 7 4 2 13 4 9 18 1 8 1 17 2 3 11 11
result:
ok 19 lines
Subtask #5:
score: 10
Accepted
Test #11:
score: 10
Accepted
time: 180ms
memory: 79580kb
input:
13459 124857 145106 107401 91905 83121 60767 3679 128709 11979 33120 3744 65889 70924 23352 121613 147007 59397 82062 79183 51935 92140 130683 123508 134140 32488 102573 29324 19916 24402 18290 84484 75957 77022 52509 137837 115089 48461 71207 59201 97041 22127 65803 147913 68572 145017 136564 22841...
output:
12 66 371 3603 12929 801 822 505 1330 2073 4554 1 783 4695 38 6 5966 1705 7 506 2733 687 71 1882 594 12100 31 1319 10868 190 27 40 736 293 7643 3121 2201 15 3553 32 1938 59 242 13073 26 27 3698 12303 237 1 92 410 2099 506 2005 10825 239 8954 42 13315 6 4139 1063 225 281 2 112 3358 185 56 2786 17 944...
result:
ok 13459 lines
Test #12:
score: 10
Accepted
time: 188ms
memory: 79684kb
input:
50001 142808 109902 126020 70745 84577 38636 139987 17708 104582 106472 52348 85215 85465 112520 80288 133706 62337 134909 61772 148908 141142 49155 66180 105880 48668 113124 133386 61278 81857 66980 14258 114615 140301 116876 72967 40191 52660 37114 106887 124015 893 128354 44454 23343 49346 103057...
output:
12479 38728 14295 13 595 22070 18 4892 35528 12479 819 17123 25511 48502 45708 9 6287 7 21738 225 62 2660 15026 3972 21071 19168 21613 37472 155 8882 42665 940 22238 15243 662 11325 10928 28758 11676 13326 1054 23144 77 23164 26600 73 91 11650 515 828 14533 634 26785 8899 613 1923 36307 7 53 46014 3...
result:
ok 50001 lines
Test #13:
score: 10
Accepted
time: 116ms
memory: 80636kb
input:
100000 822823 400187 197767 588517 322433 481751 160141 33247 311687 814063 778759 460721 553759 19819 64969 613981 5743 576421 130699 7949 910523 533129 185071 63521 292693 818123 644363 587771 72733 702707 597593 945331 566183 301789 130807 645397 701507 852139 773777 491261 824437 492227 96457 46...
output:
2 1 1 1 1 1 1 14693 1 1 1 1 1 32199 34555 1 35702 1 1 17905 1 1 1 82040 1 1 1 1 19220 1 1 1 1 1 1 1 1 1 1 1 1 1 10057 1 1 1 1 1 1 1 1 1 1 1 1 1 1 95761 8805 1 29883 14453 76000 17934 1 1 1 1 1 19441 10385 1 1 1 14230 28928 1 1 72377 1 1 1 1 1 66579 1 11630 1 1 1 78459 1 25447 1 1 1 1 1 1 89471 1 1 1...
result:
ok 100000 lines
Subtask #6:
score: 10
Accepted
Test #14:
score: 10
Accepted
time: 200ms
memory: 82784kb
input:
34209 206407 331957 399439 375407 226409 299239 316241 189067 36056 17999 32925 317503 25280 101467 109297 354553 353869 234527 362107 316769 28807 2051 300593 22296 298631 30480 167449 20358 24289 155167 5664 211007 208807 351041 327401 230149 265021 125777 338297 308423 36923 11187 33421 290219 26...
output:
21697 21697 21697 21697 21697 21697 21697 21697 970 22964 31635 21697 22332 21697 21697 21697 21697 21697 21697 21697 21697 902 21697 213 21697 4911 21697 4700 22266 21697 20401 21697 21697 21697 21697 21697 21697 21697 21697 21697 21697 5907 4483 21697 21697 21697 21697 21697 21697 21697 21697 3294...
result:
ok 34209 lines
Test #15:
score: 10
Accepted
time: 192ms
memory: 79632kb
input:
73900 53131 91320 195954 172371 143189 116804 229170 66972 186308 35691 183288 31407 102047 207348 41862 76567 150545 165024 193511 127823 75095 100734 35727 34039 53106 97402 132848 112476 76275 24240 176375 131537 77343 29213 128492 132014 143585 172627 45766 189496 26743 107057 71295 100125 18180...
output:
1482 1310 9348 10 2667 6263 180 20127 1057 59619 2708 455 4055 36303 28747 26304 71 48454 319 7458 29055 40488 49859 50838 59788 61 21518 3727 2289 24388 5102 3943 63392 895 3727 25243 4138 71648 42071 53878 46230 11720 31201 2325 469 397 65335 142 1572 59876 40 57951 36470 219 25218 36094 149 875 3...
result:
ok 73900 lines
Subtask #7:
score: 10
Accepted
Test #16:
score: 10
Accepted
time: 161ms
memory: 80628kb
input:
36118 595169 183962 697921 239481 451943 521752 590480 405542 447411 555282 696306 458731 751556 555500 603911 598570 434700 713823 549745 411601 363042 521569 676969 162260 476406 531706 391262 708855 200352 497014 532507 509778 656880 381258 487207 296725 306037 743256 673865 735047 301712 327411 ...
output:
1586 2430 1022 308 5013 3881 2864 8395 359 5257 2845 605 465 22077 31214 861 22763 9079 3941 4897 4071 34238 26500 3444 14567 16177 360 18313 2602 1890 749 496 24472 32375 5872 33442 128 13049 541 28259 3357 17860 1386 33217 2872 7066 12646 2559 2356 1699 3735 5812 497 3612 763 7696 13129 346 586 26...
result:
ok 36118 lines
Test #17:
score: 10
Accepted
time: 171ms
memory: 79092kb
input:
86023 728116 322302 695484 506104 583504 747251 455541 607160 440840 695587 703261 214164 458283 541167 548521 104063 784171 132799 218545 750242 416844 779863 238742 538188 336007 743522 197279 618188 231580 682476 776188 634123 787918 344170 275224 445912 363200 491311 761136 783887 715700 518178 ...
output:
103 45 21 3063 320 5841 55 6788 7372 3796 4353 2368 14786 5496 17 68807 15 1120 6574 51 3 62369 30722 7186 48627 97 15 538 140 96 2246 5707 854 8958 25586 1011 15230 1557 1761 4066 2104 1863 76444 80957 2 37886 33380 198 2732 69611 20 4425 77870 78322 7 23 15 3101 2678 63900 4790 7 8450 44179 178 24...
result:
ok 86023 lines
Subtask #8:
score: 10
Accepted
Test #18:
score: 10
Accepted
time: 135ms
memory: 79072kb
input:
63759 898529 358200 776048 348840 745241 787752 446992 904267 242775 488104 691984 510640 442813 537075 457000 402339 719984 551616 660491 694528 316305 517328 654787 971595 616280 694232 870181 545024 734344 585344 700024 596440 791089 885185 641888 855936 279875 993850 728128 471233 778976 402597 ...
output:
3329 33757 959 12155 3269 277 48382 967 19985 45489 598 380 122 8347 84 2178 338 27711 2346 28 55026 1323 5176 497 900 7677 2572 20 1516 456 1705 45607 4474 109 45 46685 64 1714 48709 2323 27843 896 35882 13859 35 1130 94 49902 185 1564 53 224 51 1023 6602 127 9436 627 27038 23829 1038 10899 279 37 ...
result:
ok 63759 lines
Test #19:
score: 10
Accepted
time: 209ms
memory: 82748kb
input:
98837 213448 838908 110130 830699 304514 726384 490076 93289 770619 643579 725625 711254 97489 663009 385402 385912 769492 631406 345143 828750 756937 841268 351949 828591 646858 359074 735181 795119 729465 644930 616894 102515 734314 746971 822886 632837 147249 631018 626069 152585 724465 758936 79...
output:
16 51204 36423 234 22225 6767 85 477 55 118 29435 1502 33011 2276 66823 17408 22 2184 27 69266 36 17 64 10817 49335 70296 19 17436 1096 45054 2184 2790 27117 8741 2184 21 69 112 7115 109 847 542 88 28062 34979 565 19 2464 945 317 69598 8432 5946 9596 9 157 19 348 2019 80290 20991 5014 232 23 19191 3...
result:
ok 98837 lines
Subtask #9:
score: 10
Accepted
Test #20:
score: 10
Accepted
time: 146ms
memory: 79548kb
input:
1482 730340 735966 722416 153468 886222 594024 573717 235586 994414 981720 912262 729316 838901 490383 692461 784329 401037 495726 564014 858991 886652 864500 934886 528345 698275 997694 725855 890966 331772 972439 897345 896994 775776 685193 948150 654750 562100 811680 796416 628720 901796 328689 9...
output:
282 367 137 554 83 181 34 997 28 246 719 109 293 340 55 375 57 383 130 293 373 856 80 42 111 135 698 9 69 261 479 482 1159 553 166 487 304 737 125 1340 88 24 314 527 274 710 167 1249 1075 242 503 728 301 970 164 743 17 146 203 672 247 736 884 256 138 446 1113 694 29 86 1398 1002 741 988 131 495 1265...
result:
ok 1482 lines
Test #21:
score: 10
Accepted
time: 186ms
memory: 79608kb
input:
99048 937666 990135 946447 82121 870733 113770 914518 962111 861823 960986 858198 885347 860144 985088 917869 876507 888916 880120 912777 850676 865208 989900 996178 352937 975456 955679 982971 930733 858501 854382 883258 937427 714694 980656 892995 972581 953482 991501 949874 956342 886566 915979 9...
output:
1167 2288 3698 77 4270 624 720 44283 15 1956 44 3092 34 19584 9 175 2038 94372 56 44843 84680 10507 33 96673 1223 88008 1573 95556 252 278 903 1600 23 13 1937 9 300 3495 23 23 140 72313 31461 11 4670 96920 51 163 76 3163 47 23 480 93568 52663 19 64880 6552 11447 9 298 9 501 20433 1387 6958 451 461 1...
result:
ok 99048 lines
Subtask #10:
score: 10
Accepted
Test #22:
score: 10
Accepted
time: 124ms
memory: 82748kb
input:
1176 105625 224676 1444 68921 56169 160000 576081 840889 101124 128 960400 388129 168100 166375 4356 183184 179776 176400 351649 37249 379456 1600 32400 273529 153664 321489 70225 4096 302500 672400 2500 46656 516961 806404 167281 980100 332929 783225 646416 707281 120409 70756 184900 45796 13689 55...
output:
72 5 42 346 2 350 218 146 382 199 254 146 30 373 131 44 149 254 20 555 626 1159 338 19 533 275 63 279 31 13 29 680 19 635 353 706 19 332 193 797 1072 3 133 16 107 261 379 463 267 130 94 165 355 335 419 570 19 146 103 971 142 284 27 72 146 194 437 238 28 102 74 1 174 333 227 128 19 230 256 254 783 2 ...
result:
ok 1176 lines
Test #23:
score: 10
Accepted
time: 196ms
memory: 82696kb
input:
100000 869222 817113 957851 887144 835735 939004 958453 986514 887921 986486 839270 974803 959450 856867 978220 989816 862548 984820 854777 846638 926121 803451 995772 945598 835654 836595 943416 874477 844949 832420 950219 963320 983718 811585 828626 987290 842419 921124 997447 959750 910825 890061...
output:
10 1325 9 1319 1318 122 331 114 3 1 153 3 15439 5612 12777 57 23 18383 11758 47 135 1195 17 1 8853 648 149 3 2087 367 3715 996 198 1610 1 171 3 72 121 3436 534 43 42 2935 8962 3679 20 1457 33981 152 66087 14162 3586 1 3 139 16 19354 2792 77 93 3 3 314 1076 1764 94213 7986 23370 1374 3 38 2866 111 18...
result:
ok 100000 lines
Test #24:
score: 10
Accepted
time: 231ms
memory: 79472kb
input:
100000 381720 741208 298259 53428 610711 732648 55750 575285 698715 610489 979717 133228 505858 653429 559856 867874 271791 711532 746804 19979 948096 865140 235796 483263 471943 769691 244526 924269 944742 58689 176272 81124 72857 461209 894593 308444 394854 251146 941049 927780 522386 793604 45760...
output:
575 226 26 47088 113 11286 73526 78087 621 76380 48422 66658 29249 6738 633 38 1152 19 18 48422 2754 79 148 234 48422 3 62073 47238 37 50832 1159 349 12429 28228 65 52984 29 44946 30 13306 79657 99338 1918 1936 79320 25530 48422 95850 15928 43671 1968 48422 502 13808 21858 99130 91528 201 6348 50272...
result:
ok 100000 lines
Extra Test:
score: 0
Extra Test Passed