QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#386379 | #8541. Activating Robots | lifan | 100 ✓ | 717ms | 194524kb | C++14 | 1.9kb | 2024-04-11 16:01:12 | 2024-04-11 16:01:12 |
Judging History
answer
//
#include<bits/stdc++.h>
#define int long long
using namespace std;
int L,R,n,k,a[300003],dis[100003][21],dp[(1<<20)][21],lft,rgt,mid,wz,k1,k2,k3,k4,k5,ans;
double tim;
int sqz(int X,int Y){
if(X%Y!=0)return (X/Y)+1;
return (X/Y);
}
signed main(){
ios::sync_with_stdio(false);
cin>>L>>R>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=n+1;i<=3*n;i++)a[i]=a[i-n]+L;
for(int i=0;i<=n;i++){
for(int j=0;j<=R;j++){
if(k!=1)wz=a[i]+j*(L/R)+min(sqz((R-j)*(L/R),k+1),sqz(j*(L/R),k-1));
else wz=a[i]+j*(L/R)+sqz((R-j)*(L/R),k+1);
lft=1;
rgt=3*n;
while(lft<rgt){
mid=((lft+rgt)>>1);
if(a[mid]>=wz)rgt=mid;
else lft=mid+1;
}
dis[i][j]=k*(a[lft]-(a[i]+j*(L/R)));
}
}
memset(dp,-1,sizeof(dp));
dp[1][1]=0;
for(int i=1;i<(1<<R)-1;i+=2){
for(int j=1;j<=R;j++){
if((i&(1<<j-1))==0)continue;
if(dp[i][j]==-1)continue;
wz=(L/R)*(j-1)+dp[i][j]/k;
while(wz>=L)wz-=L;
lft=1;
rgt=n+1;
while(lft<rgt){
mid=((lft+rgt)>>1);
if(a[mid]>=wz)rgt=mid;
else lft=mid+1;
}
wz=lft;
if(wz>n)wz-=n;
if(i==1&&j==1)wz=0;
for(int u=1;u<=R;u++){
if((i&(1<<(u-1)))!=0)continue;
if(u>j)k1=u-j;
else k1=(u+R-j);
if(dp[i+(1<<(u-1))][u]==-1||dp[i+(1<<(u-1))][u]>dp[i][j]+dis[wz][k1])dp[i+(1<<(u-1))][u]=dp[i][j]+dis[wz][k1];
}
}
}
ans=dp[(1<<R)-1][1];
for(int i=2;i<=R;i++){
if(dp[(1<<R)-1][i]==-1)continue;
if(ans==-1||dp[(1<<R)-1][i]<ans)ans=dp[(1<<R)-1][i];
}
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4.16667
Accepted
time: 0ms
memory: 178024kb
input:
10 2 1 2 6
output:
22
result:
ok single line: '22'
Test #2:
score: 4.16667
Accepted
time: 0ms
memory: 179008kb
input:
10 2 1 2 7
output:
4
result:
ok single line: '4'
Test #3:
score: 4.16667
Accepted
time: 0ms
memory: 179280kb
input:
32 4 5 2 0 23 12 5 11
output:
48
result:
ok single line: '48'
Test #4:
score: 4.16667
Accepted
time: 3ms
memory: 178856kb
input:
24 3 1 2 16
output:
48
result:
ok single line: '48'
Test #5:
score: 4.16667
Accepted
time: 40ms
memory: 194472kb
input:
325796798 2 100000 415814 130036882 134623756 319968467 118596706 81813191 184764752 211613431 240350767 122381690 95188488 110794026 64649345 150538562 62828748 185348390 281740201 259013226 63701012 42737041 185286671 7311148 289817702 33904049 301494116 296965958 128141108 38240586 66200241 88606...
output:
614157278
result:
ok single line: '614157278'
Test #6:
score: 4.16667
Accepted
time: 41ms
memory: 194524kb
input:
509200552 2 100000 63171 313719647 409874472 98563961 396585294 136198584 97378499 306046260 428432799 169231826 501174597 53233396 297344804 355364771 314448869 216773986 229212332 65256165 505523637 341800671 474608739 211756962 38249740 450310770 229086286 68069352 288563479 130143876 321269061 4...
output:
982688076
result:
ok single line: '982688076'
Test #7:
score: 4.16667
Accepted
time: 3ms
memory: 179236kb
input:
614228390 10 80 1 567707529 583474257 42643665 32067365 297742885 600180688 102630496 58901606 596578972 163193662 459913189 144237493 444023707 93662830 584967204 602405337 183142433 85802590 415591559 502344745 528668678 348723162 409918505 190594598 127136262 82777020 60863689 487612424 508549069...
output:
324039981
result:
ok single line: '324039981'
Test #8:
score: 4.16667
Accepted
time: 12ms
memory: 179600kb
input:
299651320 10 80 912224 168961578 236099322 69329024 270597716 232050321 209083311 249403346 83897162 279157717 82638991 251497304 160837274 148776110 144863657 152478307 199487929 160995819 4340196 276170418 253720439 214330401 258219738 47331192 285375315 259479565 3100628 145788088 262832544 86856...
output:
8573774442240
result:
ok single line: '8573774442240'
Test #9:
score: 4.16667
Accepted
time: 3ms
memory: 179476kb
input:
743972310 10 80 444351 53831864 632410420 522938004 681662893 323128224 297927355 78205776 716330383 675872450 426665635 491053574 148857585 322149372 99942542 307430259 577406843 548385688 463383589 272004828 6496438 545955891 730167532 223324091 459311029 446134253 293917701 608228397 359105211 45...
output:
2798243101221
result:
ok single line: '2798243101221'
Test #10:
score: 4.16667
Accepted
time: 12ms
memory: 179460kb
input:
665171430 10 80 353932 158645868 538045959 612775695 297958799 386960156 51539649 462476859 357296742 633121390 649090417 345677342 72407369 12619465 319757478 357208532 381958475 424956761 359733925 307111176 12628773 324426466 648079523 611883088 574352281 297742898 604807239 565969757 347260808 3...
output:
9064758440424
result:
ok single line: '9064758440424'
Test #11:
score: 4.16667
Accepted
time: 8ms
memory: 178340kb
input:
127169790 10 80 936506 39964410 108958041 102003225 125083605 79433720 104437991 85152728 62420724 107824913 50048406 31032784 26774351 96800739 101911600 83333053 98939850 27094072 98541586 31840548 74612018 41011465 112921206 68932687 107352311 106675620 112465412 51983874 2480174 59726940 8034814...
output:
6952747908816
result:
ok single line: '6952747908816'
Test #12:
score: 4.16667
Accepted
time: 7ms
memory: 178480kb
input:
114083960 10 80 215942 6829379 42408095 66085444 94087457 12335715 32322552 85150471 12044307 48247325 113884507 69509085 44779878 53685993 40140541 75025601 87088541 7542782 104042336 101114427 46206111 79812625 35168172 99521312 17413083 111526158 32755748 37395692 2347735 84524670 47404224 898702...
output:
790535373598
result:
ok single line: '790535373598'
Test #13:
score: 4.16667
Accepted
time: 160ms
memory: 194388kb
input:
604462320 16 100000 1 474034968 405571941 551954552 312068012 249243103 295665280 533416558 129347654 204569220 327641568 106755944 386106708 156615005 443411717 288517094 527561421 115510824 149485810 46800856 458057028 577820490 487049943 404716850 586267856 530207933 519574901 354385865 245507168...
output:
283427157
result:
ok single line: '283427157'
Test #14:
score: 4.16667
Accepted
time: 167ms
memory: 194456kb
input:
280520000 16 100000 2 13425246 215589280 246988696 119785555 42028716 11570723 231186671 120870879 91895072 215264953 5862286 40025638 104358996 207322003 196205111 139843402 138043819 112799988 268303073 54698130 247426866 110837436 176908185 47418782 18505573 173494299 195634023 261726826 27158047...
output:
175387934
result:
ok single line: '175387934'
Test #15:
score: 4.16667
Accepted
time: 160ms
memory: 194472kb
input:
974193232 16 100000 3 206718440 512298536 789669551 318756509 793659444 243899049 790668780 652812465 818256517 375195207 859456054 155502502 401063939 830985532 141523801 328461445 896736536 68345178 124027128 86602994 819336987 522620340 52144565 168437668 937462400 741778527 147121466 959308175 2...
output:
685310640
result:
ok single line: '685310640'
Test #16:
score: 4.16667
Accepted
time: 164ms
memory: 194392kb
input:
676090752 16 100000 262686 260571996 537618590 151294467 493673746 661994807 550419640 345856770 297595277 36997684 332130669 290081283 93897580 14315783 541526989 569709731 570243454 215277062 169441219 266811614 88354204 221912243 136854030 23126505 213590583 404773583 567546289 330123495 42577361...
output:
7240151532
result:
ok single line: '7240151532'
Test #17:
score: 4.16667
Accepted
time: 165ms
memory: 194476kb
input:
679246160 16 100000 234071 77013395 243800411 502858073 617521660 191569284 136748313 50880451 84758015 276491579 39481356 314319662 279720570 629294056 412300385 523667041 399793026 611800838 275735070 220472846 6307223 47759171 287285545 83062813 400669949 551886437 198162987 324173933 67680276 20...
output:
7802522714
result:
ok single line: '7802522714'
Test #18:
score: 4.16667
Accepted
time: 164ms
memory: 194388kb
input:
476883936 16 100000 108012 234762562 240408117 30415555 140472956 462154473 354136405 40572091 242004645 394275468 444433318 104170867 416956734 361648459 418263430 303170728 197867387 176638177 23328906 377338082 217613806 420907837 53916932 326342330 321967002 2753224 320762681 111651561 51698649 ...
output:
3096271992
result:
ok single line: '3096271992'
Test #19:
score: 4.16667
Accepted
time: 150ms
memory: 194452kb
input:
507510496 16 100000 663864 53866790 214804638 298521702 386235309 370595197 377166177 418011632 79251206 352193802 350178114 35723412 100373164 100247806 355435691 451755369 35253652 221268785 154520755 261068673 14395242 237015602 501200739 29905028 197395249 118231520 108675691 449082001 141374800...
output:
17834042496
result:
ok single line: '17834042496'
Test #20:
score: 4.16667
Accepted
time: 162ms
memory: 194452kb
input:
593679360 16 100000 306379 168642102 299060697 206475337 512602487 23373054 535063959 164981859 152255962 85828418 40158774 512366046 451752075 394221548 57919657 569807468 392816193 120984415 415048328 592692653 385727409 482807607 125053690 619913 491152927 516428234 338791756 15385741 485205200 5...
output:
6365023725
result:
ok single line: '6365023725'
Test #21:
score: 4.16667
Accepted
time: 688ms
memory: 194440kb
input:
894348360 20 100000 1 884469543 226814072 454421226 295854035 797272627 394622456 577723940 431157614 844694873 595642411 90258237 267778630 579656281 617936548 481683270 399592497 840545959 451636439 436534083 183406230 353608042 262260309 252674402 494972885 355632316 70618450 533859924 783505375 ...
output:
424977660
result:
ok single line: '424977660'
Test #22:
score: 4.16667
Accepted
time: 717ms
memory: 194472kb
input:
976034660 20 100000 2 492836120 298658168 746405489 191560699 523817619 839082997 522784842 585074485 235498803 351233093 118305896 755445786 207320083 99895488 462496799 748610155 551532558 739098419 868468295 526188148 867981270 384810831 401083017 347189112 55765243 487837848 410717201 335407832 ...
output:
618542150
result:
ok single line: '618542150'
Test #23:
score: 4.16667
Accepted
time: 679ms
memory: 194472kb
input:
224499000 20 100000 855523 135256786 158972486 76853429 63912701 155169119 48481519 39044232 84502269 69827413 110512939 116368481 135530271 152687298 110751283 38373440 87568147 151781461 154134822 95319993 38272745 21138098 185565335 192785907 218569011 48367852 155427671 32578671 224403063 154592...
output:
5734570669
result:
ok single line: '5734570669'
Test #24:
score: 4.16667
Accepted
time: 693ms
memory: 194392kb
input:
401140560 20 100000 289821 120424103 81690195 325479803 276059733 249260360 288229990 304123862 93368836 258121342 204253137 200849500 4853161 16581989 258621080 176878930 154911714 156899760 193976130 306836675 168000469 397033196 119818438 394731543 344822175 355562795 96575805 19002130 133325135 ...
output:
4836243027
result:
ok single line: '4836243027'