QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#75569 | #4899. 机器 | 4182_543_731 | 100 ✓ | 1164ms | 36080kb | C++ | 2.5kb | 2023-02-05 20:37:08 | 2023-02-05 20:37:10 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define N 2050
int n,m,v[N],s[N*10][2],a,b,as[N];
vector<int> s0[N],s1[N];
long long a1;
int head[N],cnt,cur[N],dis[N],vis[N];
struct edge{int t,next,v;}ed[N*59];
void adde(int f,int t,int v)
{
ed[++cnt]=(edge){t,head[f],v};head[f]=cnt;
ed[++cnt]=(edge){f,head[t],0};head[t]=cnt;
}
bool bfs(int s,int t)
{
queue<int> qu;
for(int i=1;i<=n+2;i++)dis[i]=-1,cur[i]=head[i];
qu.push(s);dis[s]=0;
while(!qu.empty())
{
int u=qu.front();qu.pop();
for(int i=head[u];i;i=ed[i].next)if(ed[i].v&&dis[ed[i].t]==-1)
{
dis[ed[i].t]=dis[u]+1;qu.push(ed[i].t);
if(ed[i].t==t)return 1;
}
}
return 0;
}
int dfs(int u,int t,int f)
{
if(u==t||!f)return f;
int as=0,tp;
for(int &i=cur[u];i;i=ed[i].next)
if(ed[i].v&&dis[ed[i].t]==dis[u]+1&&(tp=dfs(ed[i].t,t,min(f,ed[i].v))))
{
ed[i].v-=tp;ed[i^1].v+=tp;
as+=tp;f-=tp;
if(!f)return as;
}
return as;
}
void dfs1(int u)
{
if(vis[u])return;vis[u]=1;
for(int i=head[u];i;i=ed[i].next)if(ed[i].v)dfs1(ed[i].t);
}
void solve(vector<int> si,int l,int r)
{
if(si.empty())return;
if(l==r)
{
for(int i=0;i<si.size();i++)as[si[i]]=l;
return;
}
int mid=(l+r)>>1;
for(int i=1;i<=n+2;i++)head[i]=0;cnt=1;
for(int i=0;i<si.size();i++)
{
int u=si[i];
int rv=s0[u].end()-lower_bound(s0[u].begin(),s0[u].end(),mid+1)-(lower_bound(s1[u].begin(),s1[u].end(),mid+1)-s1[u].begin());
if(rv>=0)adde(u,n+2,rv);else adde(n+1,u,-rv);
}
for(int i=1;i<=m;i++)adde(s[i][1],s[i][0],1e9);
while(bfs(n+1,n+2))dfs(n+1,n+2,1e9);
for(int i=1;i<=n+2;i++)vis[i]=0;
dfs1(n+1);
vector<int> s1,s2;
for(int i=0;i<si.size();i++)
if(vis[si[i]])s1.push_back(si[i]);
else s2.push_back(si[i]);
solve(s1,l,mid);solve(s2,mid+1,r);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&v[i]);
for(int i=1;i<=m;i++)scanf("%d%d",&s[i][0],&s[i][1]);
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
while(a--)scanf("%d",&b),s0[i].push_back(v[i]-b);
sort(s0[i].begin(),s0[i].end());
}
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
while(a--)scanf("%d",&b),s1[i].push_back(v[i]+b);
sort(s1[i].begin(),s1[i].end());
}
vector<int> vi;
for(int i=1;i<=n;i++)vi.push_back(i);
solve(vi,0,1.1e8);
for(int i=1;i<=n;i++)
{
for(int j=0;j<s0[i].size();j++)if(s0[i][j]>as[i])a1+=s0[i][j]-as[i];
for(int j=0;j<s1[i].size();j++)if(s1[i][j]<as[i])a1+=as[i]-s1[i][j];
}
printf("%lld\n",a1);
}
詳細信息
Test #1:
score: 4
Accepted
time: 3ms
memory: 3244kb
input:
50 200 18 6 25 0 25 13 15 11 28 3 20 1 28 7 17 29 9 21 8 16 19 20 7 13 13 7 3 6 10 16 15 28 14 10 20 1 16 5 4 14 0 24 15 21 24 25 20 25 8 28 42 28 11 1 38 24 30 22 28 6 19 50 27 16 31 47 29 9 15 24 18 40 2 8 31 32 1 43 32 38 32 8 11 31 41 38 31 8 10 24 41 42 22 21 21 35 25 40 24 29 47 6 50 48 37 29 ...
output:
1936
result:
ok 1 number(s): "1936"
Test #2:
score: 4
Accepted
time: 2ms
memory: 3152kb
input:
50 200 12 17 27 19 16 26 9 12 13 26 21 21 17 9 5 0 2 8 16 19 3 17 13 19 12 1 16 9 7 2 8 12 11 27 1 19 15 2 2 28 28 15 11 7 24 8 0 26 16 16 18 33 45 3 49 15 8 4 48 16 27 49 36 23 50 13 45 7 50 15 8 32 50 28 46 30 45 46 48 4 44 2 42 28 29 2 28 17 22 23 3 21 37 4 20 6 35 1 43 47 33 43 1 34 36 2 27 31 1...
output:
1727
result:
ok 1 number(s): "1727"
Test #3:
score: 4
Accepted
time: 4ms
memory: 3400kb
input:
70 148 648 907 1017 1228 1372 708 532 3 1054 303 1488 1536 768 1812 1034 1965 1990 675 441 1821 1291 67 365 283 1754 76 1046 238 1585 173 1837 585 1080 1207 1813 804 267 697 807 1322 1000 295 1210 120 459 244 437 801 1272 879 623 563 1298 1340 846 1052 1769 245 1643 1354 418 1480 291 1850 1039 104 6...
output:
2646563
result:
ok 1 number(s): "2646563"
Test #4:
score: 4
Accepted
time: 4ms
memory: 3252kb
input:
70 178 311 290 331 1728 1193 1766 762 698 1658 1086 1760 1437 1698 949 959 154 1905 174 601 928 1257 380 1249 896 110 606 1053 702 36 135 480 347 777 1163 76 1970 1281 838 668 939 1925 781 728 1975 1730 1687 481 1987 1861 1434 1267 1470 167 517 718 277 1475 1772 979 1511 259 1811 1859 1388 974 287 1...
output:
3047983
result:
ok 1 number(s): "3047983"
Test #5:
score: 4
Accepted
time: 4ms
memory: 3536kb
input:
100 211 7523 7559 4047 9618 1325 7742 9742 3270 8367 5811 4033 2453 6391 4333 4009 1094 4351 198 3941 5230 8697 1805 9214 5042 8815 2396 6846 6052 1834 27 5114 9357 3938 9161 5328 5263 3255 5070 4886 1622 7234 8919 4075 3625 9604 4437 1071 3955 4635 1365 9185 3333 3170 4751 8375 8338 3499 1573 4390 ...
output:
35670136
result:
ok 1 number(s): "35670136"
Test #6:
score: 4
Accepted
time: 7ms
memory: 3376kb
input:
100 180 9338 5120 5309 9660 7124 5799 6588 3943 6227 8670 5407 1360 2486 7959 2074 8547 7272 9318 2800 3390 7456 6641 4697 6002 6282 3789 2206 4536 3203 9231 3215 2541 703 4876 8553 4180 7028 5141 8123 3255 3811 3530 4615 6297 7842 3041 1197 1466 2360 3997 1208 6168 6991 2257 2171 9625 6047 729 4161...
output:
34980971
result:
ok 1 number(s): "34980971"
Test #7:
score: 4
Accepted
time: 8ms
memory: 3344kb
input:
100 314 2431 3032 1166 8304 6258 5339 6169 7414 4008 5426 5943 7867 9137 455 8700 4076 667 2076 589 5564 6219 308 2784 8673 8785 2322 8077 2669 9251 3172 5982 8035 6204 3500 6339 8814 8840 2508 6228 9200 7935 8523 7068 3424 8978 5768 7501 9646 4196 4442 1562 6767 4750 699 5440 3536 3021 9869 2557 86...
output:
46092817
result:
ok 1 number(s): "46092817"
Test #8:
score: 4
Accepted
time: 5ms
memory: 3392kb
input:
100 242 3134 6290 2028 5788 4211 5174 8943 9738 3101 3465 8440 7195 3100 4581 9130 9171 8974 6008 3340 4595 7981 4673 8045 5729 318 1540 7838 8989 7999 6723 1082 7485 9365 3110 9625 3576 8284 8568 9666 7737 8386 8107 4933 7838 9040 4063 7009 8014 6424 6702 2609 757 7727 7006 2838 8045 8547 676 3386 ...
output:
44375616
result:
ok 1 number(s): "44375616"
Test #9:
score: 4
Accepted
time: 312ms
memory: 11752kb
input:
2000 4112 26779 976630 629698 838829 389521 862251 947257 514503 617805 132461 607866 44377 350873 179482 566928 325116 804117 586046 224375 835815 73008 343942 478938 803688 478006 455172 287599 664808 238219 903563 191272 781350 880193 337322 620180 786066 199574 567437 300570 817379 216251 908436...
output:
179154172171
result:
ok 1 number(s): "179154172171"
Test #10:
score: 4
Accepted
time: 332ms
memory: 11632kb
input:
2000 3078 710547 800704 389233 426297 248061 311538 298118 618533 588412 931460 691070 142844 482279 337212 753229 865200 481226 754647 810665 820379 288775 340463 672271 365043 352450 327593 902549 960185 413895 662427 693615 640795 979483 82848 67092 227545 394386 365210 362430 499150 296670 53500...
output:
153264428626
result:
ok 1 number(s): "153264428626"
Test #11:
score: 4
Accepted
time: 308ms
memory: 11520kb
input:
2000 1999 166930 540835 250286 530842 904210 505986 17302 468571 320341 513224 581776 248811 71876 479371 30498 628106 957927 593197 661712 507635 561394 190520 323163 240198 692831 142822 433859 693483 564357 825223 36798 731287 366058 287085 778481 270268 793071 795783 255192 629764 825360 353320 ...
output:
110359043397
result:
ok 1 number(s): "110359043397"
Test #12:
score: 4
Accepted
time: 329ms
memory: 11584kb
input:
2000 1999 35646 276069 424835 116267 267230 37087 581298 27990 124912 618482 760369 528816 690861 521028 749762 349949 88882 476925 488810 182877 665305 877558 195331 335562 562923 315310 824349 947080 954329 92694 720537 989975 885115 661724 622594 152345 698812 203892 696688 823724 338726 457057 8...
output:
119719819907
result:
ok 1 number(s): "119719819907"
Test #13:
score: 4
Accepted
time: 305ms
memory: 11468kb
input:
2000 1999 199132 500679 118140 685637 909027 847523 976147 601329 812769 416069 880530 460623 262867 388831 256803 198617 281793 601423 958908 845940 121803 794897 12385 222169 579451 264125 730132 449275 742264 712367 335651 941397 729399 970143 143386 154778 817666 119534 756107 146787 535603 1529...
output:
121011944346
result:
ok 1 number(s): "121011944346"
Test #14:
score: 4
Accepted
time: 312ms
memory: 11484kb
input:
2000 1999 102742 814219 224423 344676 965917 769363 97225 29938 501493 889059 290531 887011 250476 134123 143578 506965 787535 986669 201754 880684 426854 323492 809285 801746 84856 422881 589691 93040 459328 946805 765960 562070 761024 990384 423098 243293 759747 520323 273231 261240 925734 80115 6...
output:
114482929099
result:
ok 1 number(s): "114482929099"
Test #15:
score: 4
Accepted
time: 928ms
memory: 11904kb
input:
2000 7330 171682 573847 532915 243280 486629 726740 573099 137061 88552 28997 97173 410808 566361 825443 602457 965890 29871 353470 205589 559029 358645 470605 770894 406455 725513 258327 869037 243755 387236 169452 902438 75270 743299 951705 318550 746280 194797 408001 399693 799702 436999 496866 2...
output:
123030193674
result:
ok 1 number(s): "123030193674"
Test #16:
score: 4
Accepted
time: 994ms
memory: 11812kb
input:
2000 7607 404325 845008 676918 613163 630390 967208 286361 542898 406915 374830 931767 729977 339138 553105 36622 507293 534789 908280 734880 616649 659367 258274 892577 60893 725788 720867 131878 92139 977925 555591 756098 382250 400600 433016 511765 547342 400224 798127 606592 323491 172957 538360...
output:
119251622077
result:
ok 1 number(s): "119251622077"
Test #17:
score: 4
Accepted
time: 1017ms
memory: 11984kb
input:
2000 7634 767271 617869 739285 633369 699499 288381 259588 290331 184341 909322 341694 680151 320239 368895 614719 660782 637507 450080 752162 262663 290284 384380 439102 151804 647681 678043 347249 224509 596265 145724 853495 879889 763593 592780 513258 979444 397513 289198 269775 98206 714873 1278...
output:
121425993224
result:
ok 1 number(s): "121425993224"
Test #18:
score: 4
Accepted
time: 1164ms
memory: 11804kb
input:
2000 9311 742392 661409 378517 358645 329434 865533 318187 828349 727175 444809 694401 552912 782039 925216 637692 665685 388122 362136 152354 135816 395573 606486 831380 671865 172958 480502 818190 852847 107712 992255 3510 850105 170017 382027 725102 499451 763912 43289 327801 7439 4450 538554 560...
output:
120044666114
result:
ok 1 number(s): "120044666114"
Test #19:
score: 4
Accepted
time: 191ms
memory: 9044kb
input:
700 4395 1646735 65920300 11194254 55770374 76274161 68998510 5341129 69290185 47129599 85643989 18364952 43222021 62065348 44325836 26631025 71945264 37324114 4982663 26071943 59389547 99728716 82021542 53144840 45403056 70559713 97446564 39009695 89953227 69743832 62441559 34505974 71390568 283618...
output:
17260814725524
result:
ok 1 number(s): "17260814725524"
Test #20:
score: 4
Accepted
time: 200ms
memory: 9028kb
input:
700 3987 80776893 48024023 56922117 99513476 85572091 53513664 56699888 72339506 62463947 57321279 16295258 53401593 66011554 96516260 34711108 59286750 13421039 50747768 36048008 74082879 27054427 225382 90643450 80764255 98452049 54372177 43170822 77425612 23437743 35661005 1735952 4214636 8368502...
output:
17149476904162
result:
ok 1 number(s): "17149476904162"
Test #21:
score: 4
Accepted
time: 239ms
memory: 9172kb
input:
700 2051 77248002 33990513 90931860 16228511 36242991 94218392 7435649 28437336 9912862 12148530 23499796 1633656 38001802 54671579 2216823 61882777 4380956 4816250 96831980 81221708 72173269 44828393 19981207 45461866 7212970 87898361 73898127 99830141 72937472 90228803 33825193 2701827 76735668 77...
output:
16571009695053
result:
ok 1 number(s): "16571009695053"
Test #22:
score: 4
Accepted
time: 788ms
memory: 30200kb
input:
2000 14105 12630675 27636673 98454796 56909988 90317098 3305666 78143689 81191662 61177424 75289883 23130276 27288364 93849627 73256127 47103140 68892474 34134420 81259804 88530657 56711765 11011809 99961099 57107160 74254238 82425215 35398221 19156470 67290723 92181194 97264827 42161180 4811869 774...
output:
60253763960960
result:
ok 1 number(s): "60253763960960"
Test #23:
score: 4
Accepted
time: 702ms
memory: 30496kb
input:
2000 19256 47935031 93693974 18823314 34612563 34567797 37255812 63772360 74598639 60098188 16260376 63464654 81911519 31737510 70543179 88081734 23983536 26519118 34254977 43671093 38682271 99170784 47799833 8293081 49711780 8843136 5049246 99198172 85623182 956134 99480425 45818790 48891166 931743...
output:
63889555833152
result:
ok 1 number(s): "63889555833152"
Test #24:
score: 4
Accepted
time: 998ms
memory: 35920kb
input:
2000 15824 95852670 75910489 5557846 86114269 92579959 52171421 94120433 55726616 77869148 29863952 39034031 24977193 95707810 57916683 61053346 71203152 47435485 22287358 81923164 81667448 94929611 23987098 44449903 60316988 64965876 90016381 96703712 92505275 93836674 12265270 61102451 89689344 40...
output:
87693275452817
result:
ok 1 number(s): "87693275452817"
Test #25:
score: 4
Accepted
time: 1080ms
memory: 36080kb
input:
2000 20000 99622004 81222022 12621672 52959518 88799948 17290109 81969972 70200189 88434977 34886169 25284918 5712766 38356204 70141607 81940463 55482808 77518584 42110520 1955940 27741412 86495259 12006234 19169157 11814490 44811241 27825609 3986842 64703229 28969783 7421497 75156085 81108140 88643...
output:
96267890664770
result:
ok 1 number(s): "96267890664770"
Extra Test:
score: 0
Extra Test Passed