QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88503 | #3268. 寿司餐厅 | tricyzhkx | 100 ✓ | 22ms | 4380kb | C++14 | 1.6kb | 2023-03-16 13:14:38 | 2023-03-16 13:14:40 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
int s,t,a[110],c[110][110],id[110][110],d[7010],head[7010],cur[7010],to[50010],cap[50010],flow[50010],nxt[50010],tot=1;
void addedge(int u,int v,int c)
{
to[++tot]=v;
cap[tot]=c;
nxt[tot]=head[u];
head[u]=tot;
}
void add(int u,int v,int c){addedge(u,v,c);addedge(v,u,0);}
bool bfs()
{
queue<int> que;
memset(d+1,0,sizeof(int)*t);
que.push(s);d[s]=1;
while(!que.empty())
{
int u=que.front();que.pop();
for(int i=head[u];i;i=nxt[i])
{
int v=to[i];
if(cap[i]>flow[i] && !d[v]) d[v]=d[u]+1,que.push(v);
}
}
return d[t];
}
int dfs(int u,int minn)
{
if(u==t || !minn) return minn;
int ans=0,f;
for(int &i=cur[u];i;i=nxt[i])
{
int v=to[i];
if(d[v]==d[u]+1 && cap[i]>flow[i] && (f=dfs(v,min(minn,cap[i]-flow[i])))>0)
{
flow[i]+=f;flow[i^1]-=f;
ans+=f;minn-=f;
}
if(!minn) break;
}
return ans;
}
int main()
{
int n,m,cnt=1000,ans=0;
cin>>n>>m;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
scanf("%d",&c[i][j]);
for(int i=1;i<=n;i++) c[i][i]-=a[i];
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
id[i][j]=++cnt;
s=cnt+1;t=cnt+2;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
add(id[i][j],id[i][j-1],1e9),add(id[i][j],id[i+1][j],1e9);
for(int i=1;i<=n;i++) add(id[i][i],a[i],1e9);
for(int i=1;i<=1000;i++) add(i,t,m*i*i);
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
if(c[i][j]>0) add(s,id[i][j],c[i][j]),ans+=c[i][j];
else add(id[i][j],t,-c[i][j]);
while(bfs())
{
memcpy(cur+1,head+1,sizeof(int)*t);
ans-=dfs(s,1e9);
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 2ms
memory: 3668kb
input:
2 0 11 10 20 12 40
output:
51
result:
ok single line: '51'
Test #2:
score: 5
Accepted
time: 2ms
memory: 3556kb
input:
2 1 11 10 270 162 440
output:
630
result:
ok single line: '630'
Test #3:
score: 5
Accepted
time: 2ms
memory: 3700kb
input:
3 0 11 11 11 -9 40 -11 11 34 29
output:
72
result:
ok single line: '72'
Test #4:
score: 5
Accepted
time: 2ms
memory: 3728kb
input:
3 1 11 11 11 -209 440 -211 461 234 229
output:
1001
result:
ok single line: '1001'
Test #5:
score: 5
Accepted
time: 0ms
memory: 3464kb
input:
5 0 15 10 15 3 15 -12 -24 10 23 42 -14 10 24 46 -13 -32 17 -17 -18 29
output:
14
result:
ok single line: '14'
Test #6:
score: 5
Accepted
time: 2ms
memory: 3768kb
input:
5 1 15 10 15 3 15 -112 -274 160 373 442 -414 260 424 146 -163 -482 117 -217 -218 429
output:
189
result:
ok single line: '189'
Test #7:
score: 5
Accepted
time: 1ms
memory: 3688kb
input:
10 0 15 15 15 15 15 15 15 15 15 15 -29 -12 -37 24 46 -13 -32 17 -17 -18 29 37 37 -9 43 -10 42 -32 -20 44 41 6 22 -45 -19 25 -11 -44 -25 -19 -6 -36 -4 -47 -24 -19 -42 11 4 -20 19 -16 -25 40 1 -25 15 -10 18 -6 40 37 -4 -20 35
output:
140
result:
ok single line: '140'
Test #8:
score: 5
Accepted
time: 2ms
memory: 3556kb
input:
10 1 15 10 10 10 19 15 19 21 15 12 -179 -412 -337 424 146 -163 -482 117 -217 -218 429 137 487 -409 343 -360 492 -132 -320 444 491 356 122 -145 -219 425 -411 -394 -375 -319 -206 -386 -104 -397 -424 -219 -192 311 254 -120 469 -166 -225 490 351 -375 215 -110 418 -156 290 187 -454 -320 135
output:
1693
result:
ok single line: '1693'
Test #9:
score: 5
Accepted
time: 2ms
memory: 3532kb
input:
15 0 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 22 11 -50 14 32 2 -12 10 -28 -19 -9 -41 -18 46 12 -39 19 -42 45 -32 -15 40 -43 2 -33 22 -8 -21 -22 -35 -1 -22 -38 -5 -32 36 26 24 15 40 23 43 -17 -34 -4 50 -37 35 47 28 -16 -34 -35 44 -50 -33 -12 -20 -26 -26 7 -6 13 29 -8 -43 -31 18 -7 -40 -49 -22 -8...
output:
7
result:
ok single line: '7'
Test #10:
score: 5
Accepted
time: 2ms
memory: 3780kb
input:
15 1 21 21 21 21 21 21 19 17 19 19 25 19 12 21 1 -440 458 343 411 -354 356 159 243 -470 -499 -500 -272 -472 459 345 239 -434 289 -106 -267 -413 135 -136 -354 -174 185 -273 -151 495 -416 -278 464 -381 -344 -333 -418 -480 -449 -133 -455 366 -439 -363 380 402 493 -306 168 273 -289 492 -256 298 -351 -49...
output:
593
result:
ok single line: '593'
Test #11:
score: 5
Accepted
time: 0ms
memory: 3832kb
input:
30 0 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 151 353 474 427 381 -344 333 -418 -480 449 -359 455 366 439 363 493 312 -475 362 354 -463 -491 -492 443 -377 454 456 -413 305 355 452 -412 348 432 392 328 381 -431 342 414 -441 37...
output:
86969
result:
ok single line: '86969'
Test #12:
score: 5
Accepted
time: 0ms
memory: 3764kb
input:
30 0 21 21 21 24 21 20 24 21 21 24 21 30 24 21 1 21 28 21 29 21 29 21 14 24 21 28 11 14 13 8 -47 39 -34 39 -6 -17 -13 35 -36 -4 -24 35 -23 -1 45 -16 -28 14 -31 -44 -33 -18 -30 -49 -33 -5 16 -39 -13 30 2 43 -6 18 23 -39 42 -6 48 -1 -44 -5 -5 -2 12 -48 -39 -10 -6 -16 48 -31 -10 -42 -16 -16 -11 -32 13 ...
output:
169
result:
ok single line: '169'
Test #13:
score: 5
Accepted
time: 2ms
memory: 3604kb
input:
30 0 151 151 730 327 200 699 200 74 239 327 4 263 327 200 200 327 40 358 200 446 263 699 27 22 327 151 327 113 327 178 353 474 427 381 -344 333 -418 -480 449 -359 455 366 439 363 493 312 -475 362 354 -463 -491 -492 443 -377 454 456 -413 305 355 452 -412 348 432 392 328 381 -431 342 414 -441 374 -363...
output:
83602
result:
ok single line: '83602'
Test #14:
score: 5
Accepted
time: 2ms
memory: 3680kb
input:
30 1 158 270 80 80 264 264 288 23 80 158 264 158 265 264 265 23 704 80 261 100 12 23 200 80 133 126 36 270 100 264 474 305 429 495 317 474 454 -309 -328 -488 303 436 401 -374 -302 462 -494 444 312 458 471 484 391 373 -409 -486 359 480 317 -487 393 491 -500 499 -439 452 339 386 -437 403 336 -377 480 ...
output:
603
result:
ok single line: '603'
Test #15:
score: 5
Accepted
time: 2ms
memory: 3652kb
input:
50 0 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 158 -409 -486 359 480 317 -487 393 491 -500 499 -439 452 339 386 -437 403 336 -377 480 407 421 -392...
output:
243267
result:
ok single line: '243267'
Test #16:
score: 5
Accepted
time: 2ms
memory: 3936kb
input:
50 0 28 28 28 22 20 20 4 12 4 28 28 28 23 28 4 28 28 26 28 28 12 24 28 6 5 21 23 17 23 23 18 22 28 17 28 29 16 4 8 20 20 17 8 12 30 3 6 28 5 5 -27 -15 -13 33 -46 -36 -1 -24 -29 19 21 -2 44 -44 13 -40 -25 -29 -21 -26 49 46 9 15 19 -5 -17 -28 43 -23 50 -22 49 29 18 38 -41 36 -22 8 -36 -21 -48 -7 49 -3...
output:
292
result:
ok single line: '292'
Test #17:
score: 5
Accepted
time: 3ms
memory: 3656kb
input:
50 0 158 158 80 124 264 158 288 158 218 158 201 158 265 81 81 288 704 124 261 100 12 258 265 158 133 12 158 124 158 704 158 72 288 287 124 158 574 12 218 191 191 574 133 100 12 158 58 89 158 280 -409 -486 359 480 317 -487 393 491 -500 499 -439 452 339 386 -437 403 336 -377 480 407 421 -392 -377 391 ...
output:
241323
result:
ok single line: '241323'
Test #18:
score: 5
Accepted
time: 2ms
memory: 3872kb
input:
50 1 161 135 161 145 145 135 161 161 161 161 287 287 651 135 135 270 135 135 270 161 651 135 161 161 161 192 41 161 82 223 341 341 991 109 166 22 651 161 161 249 1 332 300 130 235 135 232 270 235 239 325 309 -492 389 359 317 -336 484 323 -366 -342 358 -307 385 414 364 324 458 398 396 393 476 450 397...
output:
486
result:
ok single line: '486'
Test #19:
score: 5
Accepted
time: 5ms
memory: 4092kb
input:
100 0 161 135 161 135 7 91 32 7 161 31 287 140 651 135 7 270 125 135 270 645 7 161 91 135 135 192 192 189 82 189 270 135 270 109 166 22 571 216 203 31 135 645 300 645 140 7 571 73 140 239 207 459 282 287 287 161 7 664 287 209 7 7 571 189 109 271 91 7 26 7 287 161 208 257 89 31 135 240 121 571 902 53...
output:
989019
result:
ok single line: '989019'
Test #20:
score: 5
Accepted
time: 22ms
memory: 4380kb
input:
100 1 161 135 161 135 7 91 32 7 161 31 287 140 651 135 7 270 125 135 270 645 7 161 91 135 135 192 192 189 82 189 270 135 270 109 166 22 571 216 203 31 135 645 300 645 140 7 571 73 140 239 207 459 282 287 287 161 7 664 287 209 7 7 571 189 109 271 91 7 26 7 287 161 208 257 89 31 135 240 121 571 902 53...
output:
3255
result:
ok single line: '3255'