QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#325321 | #5616. Which Warehouse? | weilaifuture# | AC ✓ | 32ms | 6200kb | C++14 | 2.3kb | 2024-02-11 08:01:39 | 2024-02-11 08:01:40 |
Judging History
answer
#include<bits/stdc++.h>
#define N 205
#define M 100005
using namespace std;
const long long INF=5e17;
long long s,vst[N],inq[N],t,tot,cnt=1,to[M],cost,x,y,nxt[M],head[N],c[M],d[N],cur[N],n,m,f[M];
long long a[N][N],dis[N][N];
long long read(){
long long x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
void Write(long long x){
short st[20]; int tp=0;
st[++tp]=x%10; x/=10;
while(x){st[++tp]=x%10; x/=10;}
while(tp){putchar(st[tp]|'0'); tp--;}
}
inline void add(int x,int y,long long z,long long fy){
to[++cnt]=y; nxt[cnt]=head[x]; c[cnt]=z; f[cnt]=fy; head[x]=cnt;
to[++cnt]=x; nxt[cnt]=head[y]; c[cnt]=0; f[cnt]=-fy; head[y]=cnt;
}
bool bfs(){
memset(inq,0,sizeof(inq));
for(int i=1;i<=t;i++) d[i]=INF;
queue<int> q; d[s]=0; q.push(s); cur[s]=head[s]; inq[s]=1;
while(!q.empty()){
int u=q.front(); q.pop(); inq[u]=0;
for(int i=head[u],v;i;i=nxt[i]){
v=to[i];
if(c[i]&&d[v]>f[i]+d[u]){
d[v]=d[u]+f[i]; cur[v]=head[v];
if(!inq[v]) q.push(v),inq[v]=1;
}
}
}
return (d[t]!=INF);
}
long long dfs(int x,long long limit){
if(x==t) return limit;
vst[x]=1;
long long flow=0;
for(int i=cur[x],v;i&&flow<=limit;i=nxt[i]){
v=to[i]; cur[x]=i;
if(c[i]&&d[v]==d[x]+f[i]&&!vst[v]){
long long fl=dfs(v,min(limit-flow,c[i]));
flow+=fl; c[i]-=fl; c[i^1]+=fl; cost+=fl*f[i];
}
}
return flow;
}
long long dinic(){
long long maxflow=0,flow=0;
while(bfs()){
memset(vst,0,sizeof(vst));
while(flow=dfs(s,INF)){
maxflow+=flow;
}
}
return maxflow;
}
int main(){
n=read(); m=read();
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=read();
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){dis[j][i]=read(); if(dis[j][i]==-1) dis[j][i]=INF;}
for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dis[i][j]=min(dis[i][k]+dis[k][j], dis[i][j]);
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
long long cst=0;
for(int k=1;k<=n;k++) cst+=(dis[i][k]*a[k][j]);
add(i,j+n,1,cst);
}
s=n+m+1; t=n+m+2;
for(int i=1;i<=n;i++) add(s,i,1,0); for(int i=1;i<=m;i++) add(i+n,t,1,0);
dinic();
Write(cost);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3604kb
input:
3 2 5 10 0 6 7 3 0 3 5 3 0 9 5 9 0
output:
58
result:
ok single line: '58'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
3 2 5 10 0 6 7 3 0 -1 5 -1 0 9 5 9 0
output:
124
result:
ok single line: '124'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5796kb
input:
1 1 10 0
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2 1 0 10 0 1 1 0
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
2 1 12 10 0 1 1 0
output:
10
result:
ok single line: '10'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
2 1 10 10 0 1 2 0
output:
10
result:
ok single line: '10'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
2 2 10 12 13 11 0 1 1 0
output:
21
result:
ok single line: '21'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
2 2 12 10 11 13 0 1 1 0
output:
21
result:
ok single line: '21'
Test #9:
score: 0
Accepted
time: 32ms
memory: 6064kb
input:
100 100 365 555 860 485 544 213 501 267 715 120 175 86 740 213 481 240 201 850 108 851 136 240 79 773 818 987 856 81 994 367 6 854 459 59 435 406 831 413 271 613 268 682 440 668 808 264 974 809 966 106 986 445 313 415 343 457 269 703 857 734 181 387 817 768 854 768 882 886 443 8 534 808 962 493 146 ...
output:
31843360
result:
ok single line: '31843360'
Test #10:
score: 0
Accepted
time: 31ms
memory: 6140kb
input:
100 100 371 169 496 501 256 720 700 567 201 380 805 166 541 813 431 334 195 581 1 853 252 696 804 782 485 331 380 843 538 504 417 366 375 107 255 572 639 293 257 487 856 514 620 398 926 737 39 731 635 239 769 776 544 768 563 47 677 260 388 277 28 866 99 106 340 916 391 392 217 670 963 822 449 732 15...
output:
32792136
result:
ok single line: '32792136'
Test #11:
score: 0
Accepted
time: 1ms
memory: 5652kb
input:
15 1 265 382 436 518 302 299 301 14 365 635 680 538 274 968 345 0 7 16 22 84 69 11 23 74 80 49 37 47 7 20 24 0 67 87 12 77 95 73 91 88 65 4 63 48 97 74 10 0 8 48 93 81 22 91 89 30 15 44 73 72 80 3 19 0 30 10 44 62 80 86 47 31 6 76 42 32 70 86 47 0 10 28 60 52 57 34 32 80 70 98 96 44 40 4 47 0 48 32 ...
output:
104227
result:
ok single line: '104227'
Test #12:
score: 0
Accepted
time: 0ms
memory: 5624kb
input:
15 2 265 0 382 0 436 0 518 0 302 0 299 0 301 0 14 0 365 0 635 0 680 0 538 0 274 392 968 0 345 0 0 7 16 22 84 69 11 23 74 80 49 37 47 7 20 24 0 67 87 12 77 95 73 91 88 65 4 63 48 97 74 10 0 8 48 93 81 22 91 89 30 15 44 73 72 80 3 19 0 30 10 44 62 80 86 47 31 6 76 42 32 70 86 47 0 10 28 60 52 57 34 32...
output:
111283
result:
ok single line: '111283'
Test #13:
score: 0
Accepted
time: 1ms
memory: 5624kb
input:
15 2 265 0 382 0 436 0 518 0 302 0 299 0 301 0 14 0 365 0 635 0 680 0 538 0 274 393 968 0 345 0 0 7 16 22 84 69 11 23 74 80 49 37 47 7 20 24 0 67 87 12 77 95 73 91 88 65 4 63 48 97 74 10 0 8 48 93 81 22 91 89 30 15 44 73 72 80 3 19 0 30 10 44 62 80 86 47 31 6 76 42 32 70 86 47 0 10 28 60 52 57 34 32...
output:
111294
result:
ok single line: '111294'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
10 10 775 944 857 998 921 239 887 998 520 870 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 -1 -1 -1 -1 -1 -1 -1 1 0 1 -1 -1 -1 -1 -1 -1 -1 -1 1 0 1 -1 -1 -1 -...
output:
30425
result:
ok single line: '30425'
Test #15:
score: 0
Accepted
time: 0ms
memory: 5852kb
input:
10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 264 378 978 85 415 701 716 924 613 794 0 1 -1 -1 -1 -1 -1 -1 -1 -1 1 0 1 -1 -1 -1 -1 -1 -1 -1 -1 1 0 1 -1 -1 -1 -1...
output:
18542
result:
ok single line: '18542'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 513 990 883 755 236 485 72 167 753 764 891 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
output:
22318
result:
ok single line: '22318'
Test #17:
score: 0
Accepted
time: 1ms
memory: 5608kb
input:
9 4 10 0 10 0 0 0 0 0 10 10 0 0 0 0 0 0 10 10 10 10 0 0 0 0 0 0 10 10 0 0 0 0 0 10 0 10 0 1 -1 1 -1 -1 -1 -1 -1 1 0 1 -1 1 -1 -1 -1 -1 -1 1 0 -1 -1 1 -1 -1 -1 1 -1 -1 0 1 -1 1 -1 -1 -1 1 -1 1 0 1 -1 1 -1 -1 -1 1 -1 1 0 -1 -1 1 -1 -1 -1 1 -1 -1 0 1 -1 -1 -1 -1 -1 1 -1 1 0 1 -1 -1 -1 -1 -1 1 -1 1 0
output:
120
result:
ok single line: '120'
Test #18:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
30 1 877 703 970 927 405 582 743 582 471 425 0 373 35 729 510 406 408 824 48 521 969 333 110 4 743 825 438 198 919 638 0 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
output:
15716
result:
ok single line: '15716'
Test #19:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
3 3 10 13 13 1 1 1 1 3 2 0 1 1 1 0 1 1 1 0
output:
28
result:
ok single line: '28'
Test #20:
score: 0
Accepted
time: 1ms
memory: 5816kb
input:
4 4 32 63 1 1 32 1 63 1 32 1 1 63 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0
output:
105
result:
ok single line: '105'
Test #21:
score: 0
Accepted
time: 2ms
memory: 5876kb
input:
54 31 195 128 289 229 864 989 739 721 834 811 351 767 836 90 61 852 303 298 227 597 364 940 644 884 391 680 140 745 180 516 62 17 740 389 950 253 495 493 794 913 421 426 3 599 16 863 194 927 241 705 365 662 459 144 864 585 477 520 744 84 88 91 12 651 496 180 44 427 528 83 243 342 694 640 225 250 173...
output:
5921761
result:
ok single line: '5921761'
Test #22:
score: 0
Accepted
time: 8ms
memory: 4252kb
input:
98 51 326 189 769 769 400 404 255 574 713 737 254 903 916 8 474 131 452 690 684 367 523 87 45 127 978 381 1000 65 483 640 370 127 778 502 565 847 842 334 864 80 500 588 74 731 617 947 253 900 801 320 288 155 557 406 453 3 430 140 321 751 856 303 809 76 649 741 338 143 172 439 185 531 554 162 321 79 ...
output:
16031302
result:
ok single line: '16031302'
Test #23:
score: 0
Accepted
time: 5ms
memory: 4240kb
input:
78 47 760 1 338 479 348 99 487 599 222 395 256 786 340 211 596 234 616 819 93 440 23 124 110 356 225 248 985 63 185 396 657 446 859 246 622 894 861 465 847 78 694 226 690 669 964 767 383 457 642 707 971 617 709 40 391 216 192 873 296 342 934 987 386 501 156 304 990 157 313 103 867 964 357 179 440 27...
output:
12505597
result:
ok single line: '12505597'
Test #24:
score: 0
Accepted
time: 2ms
memory: 3892kb
input:
51 34 713 158 954 38 368 362 599 594 974 909 941 402 304 161 377 674 97 269 326 342 177 509 725 663 856 391 416 537 3 708 960 812 879 824 182 997 4 968 62 497 808 496 416 677 397 23 89 581 292 735 510 711 712 740 512 883 672 777 419 994 580 313 664 703 913 41 715 630 351 63 591 912 655 126 756 816 2...
output:
7358556
result:
ok single line: '7358556'
Test #25:
score: 0
Accepted
time: 6ms
memory: 5960kb
input:
81 49 934 168 504 321 472 177 942 501 989 147 65 365 451 377 151 285 252 773 142 793 867 660 344 157 803 675 341 700 619 141 295 843 726 354 792 632 856 637 39 252 290 738 514 787 198 314 174 388 414 812 465 337 31 634 184 421 891 365 77 124 596 246 241 244 84 619 15 862 393 601 48 457 910 132 923 4...
output:
11769727
result:
ok single line: '11769727'
Test #26:
score: 0
Accepted
time: 26ms
memory: 6064kb
input:
97 92 93 724 989 467 672 419 405 910 901 716 700 948 735 177 160 66 144 575 554 252 737 383 16 584 212 340 612 568 877 948 857 738 327 822 445 405 258 902 442 226 162 311 671 877 460 686 988 942 25 774 114 513 805 590 825 526 177 275 507 549 844 203 165 730 952 896 718 400 145 324 928 430 480 167 47...
output:
29083791
result:
ok single line: '29083791'
Test #27:
score: 0
Accepted
time: 9ms
memory: 6080kb
input:
94 58 224 612 765 809 378 809 921 310 546 850 731 31 402 713 626 786 239 410 915 644 47 623 835 950 582 855 73 912 751 795 610 980 527 901 782 282 542 925 680 804 47 569 908 397 327 304 528 98 554 907 5 341 496 56 743 194 847 757 783 385 858 213 34 399 511 946 362 776 207 600 570 997 294 442 959 445...
output:
17071864
result:
ok single line: '17071864'
Test #28:
score: 0
Accepted
time: 11ms
memory: 6016kb
input:
97 63 79 194 999 538 496 55 482 337 689 83 909 81 324 732 780 35 90 935 897 597 262 22 396 861 549 886 572 587 738 140 732 593 70 68 832 882 516 110 166 404 859 669 994 139 36 829 370 195 171 417 984 698 283 134 726 320 266 543 691 965 260 397 4 573 211 115 406 554 707 468 855 326 412 601 732 658 34...
output:
21270663
result:
ok single line: '21270663'
Test #29:
score: 0
Accepted
time: 3ms
memory: 5904kb
input:
78 51 378 695 249 77 810 255 912 972 475 670 245 865 928 765 442 938 675 120 671 830 74 345 319 313 386 442 762 172 952 443 574 480 487 276 406 871 779 431 445 400 492 542 451 533 942 356 230 898 109 755 116 668 278 409 5 12 753 263 517 151 691 281 751 403 815 539 85 360 348 349 611 824 914 85 28 54...
output:
14410314
result:
ok single line: '14410314'
Test #30:
score: 0
Accepted
time: 11ms
memory: 4276kb
input:
92 73 307 719 300 137 354 145 312 115 182 991 372 435 479 964 960 783 350 824 607 542 992 479 113 399 471 451 610 607 955 950 912 837 935 904 922 612 320 961 579 981 977 467 382 21 601 935 340 250 534 379 808 518 403 149 532 430 229 567 300 177 595 455 568 872 179 825 432 319 314 763 768 213 483 205...
output:
22136855
result:
ok single line: '22136855'
Test #31:
score: 0
Accepted
time: 24ms
memory: 6200kb
input:
96 90 93 974 157 721 351 410 187 56 744 580 607 900 83 954 469 23 205 475 731 191 418 968 850 428 683 704 414 683 795 342 24 347 593 441 493 259 728 552 631 799 753 568 785 221 978 59 976 240 216 7 197 8 216 104 624 708 4 43 782 742 881 168 170 649 820 586 842 729 548 567 848 222 491 383 201 223 951...
output:
31498263
result:
ok single line: '31498263'