QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282538 | #6306. Chase Game | chenxinyang2006 | AC ✓ | 78ms | 13404kb | C++14 | 2.6kb | 2023-12-12 11:47:50 | 2023-12-12 11:47:50 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int n,m,k,d;
int _u[200005],_v[200005];
int cnt;
int head[100005];
struct eg{
int to,nxt,w;
}edge[500005];
void make(int u,int v,int w){
// printf("%d->%d %d\n",u,v,w);
edge[++cnt].to = v;
edge[cnt].w = w;
edge[cnt].nxt = head[u];
head[u] = cnt;
}
ll dist[100005];
priority_queue <pll> Q;
void dijsktra(int sour){
memset(dist,0x3f,sizeof(dist));
dist[sour] = 0;
Q.push(mkp(0,sour));
while(!Q.empty()){
pll cur = Q.top();
Q.pop();
if(dist[cur.second] < -cur.first) continue;
int u = cur.second;
for(int i = head[u];i;i = edge[i].nxt){
int v = edge[i].to;
if(dist[v] > dist[u] + edge[i].w){
dist[v] = dist[u] + edge[i].w;
Q.push(mkp(-dist[v],v));
}
}
}
}
int dis[2][100005];
ll calc(int p){
int r = p / d;
ll sum = 1ll * d * (d + 1) / 2 * r;
p %= d;
sum += 1ll * (d + d - p + 1) * p / 2;
return sum;
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d%d%d%d",&n,&m,&k,&d);
rep(i,1,m){
scanf("%d%d",&_u[i],&_v[i]);
make(_u[i],_v[i],1);
make(_v[i],_u[i],1);
}
dijsktra(n);
rep(u,1,n) dis[0][u] = dist[u];
dijsktra(k);
rep(u,1,n) dis[1][u] = dist[u];
/* rep(u,1,n) printf("%d ",dis[0][u]);
printf("\n");
rep(u,1,n) printf("%d ",dis[1][u]);
printf("\n"); */
// printf("awa\n");
cnt = 0;
memset(head,0,sizeof(head));
rep(i,1,m){
if(dis[1][_u[i]] < d || _u[i] == 1) make(_u[i],_v[i],max(0,d - dis[1][_v[i]]));
if(dis[1][_v[i]] < d || _v[i] == 1) make(_v[i],_u[i],max(0,d - dis[1][_u[i]]));
}
dijsktra(1);
ll ans = linf;
if(dis[1][n] < d) chkmin(ans,dist[n]);
rep(u,1,n){
if(dis[1][u] < d) continue;
// printf("u=%d %lld\n",u,calc(dis[0][u] + 1));
chkmin(ans,dist[u] + calc(dis[0][u] + 1));
}
printf("%lld\n",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4892kb
input:
5 5 3 1 1 2 2 4 4 5 1 3 3 5
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 6520kb
input:
13 17 12 3 1 2 2 3 3 4 4 13 5 13 7 8 7 9 7 10 7 11 7 6 12 7 1 8 8 9 9 10 10 11 11 6 6 13
output:
7
result:
ok 1 number(s): "7"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7912kb
input:
10 9 4 1 4 3 1 2 7 6 6 5 8 9 9 10 5 4 8 7 3 2
output:
9
result:
ok 1 number(s): "9"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7832kb
input:
10 20 9 1 9 5 2 9 4 5 10 5 7 3 1 8 7 1 7 5 3 4 3 1 7 8 3 8 9 3 10 6 9 1 1 6 8 5 6 2 1 10 2 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 8000kb
input:
10 20 3 1 1 4 6 7 5 4 5 3 2 1 8 1 7 8 2 6 2 4 4 8 9 5 1 10 7 4 5 8 4 10 2 5 6 10 4 6 3 7 1 3
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 7960kb
input:
10 20 4 1 2 7 6 4 2 3 2 4 6 5 8 5 6 7 10 2 3 10 1 8 3 9 3 7 1 7 5 1 6 1 3 4 2 1 5 2 9 2 9 10
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
10 20 1 10 10 9 2 5 7 8 7 10 10 8 8 9 5 6 3 1 6 4 7 9 2 3 3 6 2 1 8 6 5 8 7 4 4 3 2 4 4 1 9 6
output:
24
result:
ok 1 number(s): "24"
Test #8:
score: 0
Accepted
time: 1ms
memory: 7732kb
input:
10 20 6 10 5 4 1 7 6 8 1 2 6 1 5 2 5 1 2 4 5 3 3 2 10 3 9 10 7 9 3 1 5 9 1 8 8 3 8 7 6 4 2 7
output:
15
result:
ok 1 number(s): "15"
Test #9:
score: 0
Accepted
time: 1ms
memory: 7968kb
input:
1000 999 387 1 505 506 314 313 410 411 680 681 884 885 491 492 60 59 343 342 396 397 880 881 954 953 833 834 53 54 284 283 794 793 241 240 347 348 89 88 787 786 551 550 673 672 56 57 683 682 168 169 814 813 726 725 877 876 981 982 799 800 228 227 568 569 387 386 211 212 30 29 298 299 514 515 561 562...
output:
999
result:
ok 1 number(s): "999"
Test #10:
score: 0
Accepted
time: 1ms
memory: 6540kb
input:
1000 2000 879 1 357 547 380 111 973 995 179 906 478 508 463 822 687 488 70 40 330 202 189 303 103 39 510 743 1000 236 311 695 29 338 156 77 299 249 289 275 419 57 352 704 739 825 676 194 783 828 769 169 270 325 354 29 145 197 309 461 456 461 997 816 478 387 117 626 931 803 445 91 730 160 1000 322 25...
output:
3
result:
ok 1 number(s): "3"
Test #11:
score: 0
Accepted
time: 1ms
memory: 6772kb
input:
1000 2000 603 228 10 11 885 884 217 218 626 629 559 562 305 302 328 326 809 807 176 179 553 554 435 432 641 639 761 763 486 484 376 374 261 260 515 512 224 222 413 414 33 34 468 470 976 979 461 459 491 490 272 275 528 526 393 396 673 676 45 42 677 676 247 249 938 937 200 203 649 647 303 304 457 455 ...
output:
49209
result:
ok 1 number(s): "49209"
Test #12:
score: 0
Accepted
time: 2ms
memory: 6736kb
input:
1000 2000 943 363 702 699 676 678 81 82 643 646 439 436 12 11 665 663 288 289 143 141 476 478 559 558 251 250 845 842 912 911 818 816 559 557 69 68 448 450 693 696 527 524 323 322 207 208 436 434 39 38 756 759 721 723 785 787 719 718 688 687 343 345 825 822 834 833 792 791 475 476 777 779 975 972 32...
output:
74162
result:
ok 1 number(s): "74162"
Test #13:
score: 0
Accepted
time: 0ms
memory: 7968kb
input:
1000 2000 413 19 116 130 388 369 137 111 500 505 463 475 292 310 75 77 545 516 131 161 281 304 715 725 221 250 280 301 267 260 881 897 564 546 684 680 416 435 882 886 18 44 965 967 891 867 530 517 14 1 930 923 192 176 971 974 139 160 949 955 293 313 10 5 25 40 181 157 614 632 573 595 701 725 33 27 1...
output:
442
result:
ok 1 number(s): "442"
Test #14:
score: 0
Accepted
time: 2ms
memory: 7928kb
input:
1000 2000 970 42 924 920 773 772 926 923 887 916 143 121 525 547 17 3 55 63 884 871 840 853 821 846 161 155 87 83 515 521 146 168 940 911 881 876 107 84 898 920 156 144 489 518 706 709 599 569 396 420 806 808 68 48 619 645 407 411 955 951 144 160 173 167 243 240 217 195 191 205 729 750 809 796 914 9...
output:
1026
result:
ok 1 number(s): "1026"
Test #15:
score: 0
Accepted
time: 2ms
memory: 7812kb
input:
1000 2000 466 3 538 855 15 123 584 118 168 66 48 428 142 111 346 49 61 295 324 209 310 293 318 201 215 286 602 379 11 106 430 90 286 255 323 155 238 446 387 332 469 652 696 673 122 79 3 69 497 937 500 683 490 200 331 237 71 92 5 651 626 691 265 832 543 832 370 693 723 362 390 923 1 353 64 629 259 52...
output:
9
result:
ok 1 number(s): "9"
Test #16:
score: 0
Accepted
time: 0ms
memory: 6800kb
input:
1000 2000 746 4 7 415 55 519 357 437 904 700 23 855 898 527 7 19 66 645 596 341 829 658 369 240 1 213 491 775 980 193 8 131 788 159 446 480 740 862 412 476 631 566 288 323 702 748 904 801 235 899 791 321 56 559 17 2 918 990 189 348 628 303 540 758 834 46 643 142 799 256 264 548 844 79 707 440 16 42 ...
output:
10
result:
ok 1 number(s): "10"
Test #17:
score: 0
Accepted
time: 2ms
memory: 7948kb
input:
1000 2000 870 1000 619 621 497 500 23 22 775 774 60 62 790 793 86 85 968 965 994 997 200 203 218 221 869 867 160 158 839 840 695 693 914 915 323 324 879 876 433 430 707 709 523 522 567 565 906 905 499 497 317 320 345 344 483 486 787 785 478 475 13 16 8 9 299 297 159 156 694 692 404 402 762 759 851 8...
output:
325057
result:
ok 1 number(s): "325057"
Test #18:
score: 0
Accepted
time: 0ms
memory: 6920kb
input:
1000 2000 504 1000 500 470 889 915 407 429 63 44 428 437 768 754 29 44 513 504 284 282 915 893 34 19 154 142 565 566 494 465 549 541 970 946 589 594 858 866 843 848 564 583 481 474 709 691 295 284 719 724 981 987 168 176 161 164 152 128 250 269 635 650 932 956 310 328 583 586 799 803 530 535 476 491...
output:
44466
result:
ok 1 number(s): "44466"
Test #19:
score: 0
Accepted
time: 2ms
memory: 6620kb
input:
1000 2000 484 1000 730 564 103 147 467 212 346 38 376 753 126 600 82 553 265 237 836 228 777 142 363 940 242 106 74 73 249 14 516 682 171 51 842 946 517 565 492 726 104 146 701 371 232 396 559 687 777 525 1 84 85 104 598 46 651 545 716 139 738 421 10 3 474 301 313 830 256 229 329 534 133 717 67 725 ...
output:
3984
result:
ok 1 number(s): "3984"
Test #20:
score: 0
Accepted
time: 18ms
memory: 10176kb
input:
100000 99999 80116 1 34647 34648 67776 67777 6092 6091 4913 4912 88063 88064 91537 91536 64312 64311 97104 97103 46206 46207 12613 12612 2989 2988 59399 59398 36992 36991 877 876 66200 66199 48320 48319 99684 99685 86436 86437 22549 22548 53368 53367 70760 70759 66290 66291 75023 75024 25613 25612 6...
output:
99999
result:
ok 1 number(s): "99999"
Test #21:
score: 0
Accepted
time: 59ms
memory: 13236kb
input:
100000 200000 2392 1 60010 3447 47231 2838 2866 18129 1178 6806 61915 71422 30169 784 56653 55634 31374 59835 58351 88377 49937 57524 7477 39347 16036 19714 95741 29161 68786 18742 55515 29139 29310 18531 680 540 23647 27407 33056 7940 32885 1503 4416 5340 14479 89169 18845 51882 13637 10967 8370 63...
output:
7
result:
ok 1 number(s): "7"
Test #22:
score: 0
Accepted
time: 17ms
memory: 10824kb
input:
100000 99999 97166 97165 45763 45762 55286 55287 51139 51138 25612 25613 90370 90371 46591 46592 71822 71821 79333 79332 52338 52337 92408 92407 65146 65145 89830 89831 26985 26984 59909 59910 88252 88251 7097 7096 31186 31185 72182 72183 54666 54667 19127 19126 15426 15427 51083 51084 87216 87217 2...
output:
4991915610
result:
ok 1 number(s): "4991915610"
Test #23:
score: 0
Accepted
time: 19ms
memory: 10664kb
input:
100000 99999 98438 98436 30075 30074 11398 11399 11010 11009 55659 55658 3338 3339 99851 99850 86315 86314 88236 88235 42281 42282 2676 2675 75467 75468 93688 93689 37051 37050 31697 31696 22674 22673 28607 28608 86743 86744 37290 37289 32441 32440 56434 56433 84187 84188 52628 52627 59705 59706 971...
output:
4997507031
result:
ok 1 number(s): "4997507031"
Test #24:
score: 0
Accepted
time: 40ms
memory: 13240kb
input:
100000 200000 61169 2626 26064 26045 70667 70664 20364 20382 23250 23266 9249 9278 99096 99074 91839 91826 96552 96574 92722 92746 41088 41072 26988 26976 74143 74140 21564 21546 90711 90709 68203 68176 20345 20371 1947 1937 75241 75231 31961 31983 94360 94345 69684 69669 9027 9032 14482 14497 10392...
output:
6441740
result:
ok 1 number(s): "6441740"
Test #25:
score: 0
Accepted
time: 36ms
memory: 13192kb
input:
100000 200000 87495 3767 60847 60848 86404 86419 86435 86414 57400 57389 32874 32865 96235 96234 73216 73208 59361 59372 99956 99979 83195 83187 98911 98920 6185 6171 20398 20385 49481 49451 66846 66852 56360 56341 74056 74041 65924 65938 42480 42459 98091 98077 797 794 96521 96509 55706 55717 95198...
output:
8995356
result:
ok 1 number(s): "8995356"
Test #26:
score: 0
Accepted
time: 54ms
memory: 13264kb
input:
100000 200000 78226 333 66299 66382 32606 32329 74851 74700 34893 35005 27655 27757 67589 67846 22689 22788 35374 35635 67807 67645 39276 39067 70259 70101 98403 98640 78045 78037 91162 91219 29757 29901 89377 89479 75094 75358 15259 15290 45798 46013 13958 13959 73041 73295 72249 71955 37783 37614 ...
output:
81407
result:
ok 1 number(s): "81407"
Test #27:
score: 0
Accepted
time: 48ms
memory: 13024kb
input:
100000 200000 38355 163 30866 31152 87877 88012 23652 23602 53424 53185 47038 46783 73084 73238 78086 77967 19087 19135 72342 72334 13614 13588 94694 94706 98305 98170 18746 18576 55325 55419 32032 32127 77512 77697 62472 62608 96152 96249 20854 21073 43002 43161 15032 15016 92035 92064 25834 26005 ...
output:
37887
result:
ok 1 number(s): "37887"
Test #28:
score: 0
Accepted
time: 57ms
memory: 13404kb
input:
100000 200000 76471 6 21617 13990 17758 15109 15047 13772 61038 63549 32148 10326 18790 19284 24211 87724 67009 17560 2734 3784 18823 29098 62214 91946 91932 60696 20950 8263 20704 64013 4810 23069 4161 25199 38216 21283 16374 4822 49988 98301 52561 28075 41379 80854 42633 1953 3743 2821 31985 42456...
output:
27
result:
ok 1 number(s): "27"
Test #29:
score: 0
Accepted
time: 59ms
memory: 13348kb
input:
100000 200000 12452 3 7747 39881 6731 9144 18372 76959 23127 57956 61106 63877 8684 1597 87132 33575 18344 8993 44409 36831 4300 13217 41001 67654 14839 25176 32242 90631 34040 23231 20391 32209 38825 96859 20238 22934 12083 6614 41287 51910 10320 15300 65619 64864 52419 17568 23406 11910 40482 3963...
output:
11
result:
ok 1 number(s): "11"
Test #30:
score: 0
Accepted
time: 45ms
memory: 13004kb
input:
100000 200000 4431 100000 96288 96298 87771 87800 65620 65626 12105 12076 83228 83251 68186 68188 70260 70236 81322 81309 71065 71058 29837 29842 41483 41512 37953 37968 24957 24954 12451 12473 67775 67764 77327 77305 72125 72102 7032 7029 73915 73913 31163 31146 32983 32986 32896 32916 39230 39256 ...
output:
422308469
result:
ok 1 number(s): "422308469"
Test #31:
score: 0
Accepted
time: 51ms
memory: 13028kb
input:
100000 200000 79595 100000 97088 97332 82519 82815 78378 78374 82967 82734 95521 95346 33593 33650 54200 54244 64181 64140 90001 89725 58491 58565 54697 54435 23976 24063 52801 53061 15857 15988 4914 4920 513 569 89160 89411 21164 21408 11232 10972 84525 84307 8564 8415 29985 30283 75578 75409 58743...
output:
42238874
result:
ok 1 number(s): "42238874"
Test #32:
score: 0
Accepted
time: 78ms
memory: 13208kb
input:
100000 200000 64272 100000 21953 32449 93406 90260 19016 85724 8208 60369 3470 3948 60449 58810 8954 15921 84884 58099 2863 1386 36753 68219 80737 41404 3260 9845 4632 52637 21986 22216 26692 42844 53249 25958 10228 14389 11104 63163 12792 29952 9442 13618 31960 6446 43957 11053 99377 7930 34737 919...
output:
599960
result:
ok 1 number(s): "599960"