QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#276729 | #3268. 寿司餐厅 | SoyTony | 100 ✓ | 19ms | 6140kb | C++14 | 2.7kb | 2023-12-06 10:08:55 | 2023-12-06 10:08:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=10205;
const int maxm=1e5+10;
inline int read(){
int x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
int n,m;
int a[105],id_a[1005];
int d[105][105],id[105][105];
int sum;
bool vis[1005];
int S,T,tot;
struct Graph{
struct edge{
int to,nxt,lim;
}e[maxm<<1];
int head[maxn],cnt=1;
inline void add_edge(int u,int v,int w){
e[++cnt].to=v,e[cnt].nxt=head[u],e[cnt].lim=w,head[u]=cnt;
e[++cnt].to=u,e[cnt].nxt=head[v],e[cnt].lim=0,head[v]=cnt;
}
int cur[maxn],dis[maxn];
int dfs(int u,int rest){
if(u==T) return rest;
int flow=0;
for(int i=cur[u];i&&rest;i=e[i].nxt){
cur[u]=i;
int v=e[i].to,C=min(rest,e[i].lim);
if(dis[u]+1==dis[v]&&C){
int k=dfs(v,C);
flow+=k,rest-=k;
e[i].lim-=k,e[i^1].lim+=k;
}
}
if(!flow) dis[u]=-1;
return flow;
}
inline int max_flow(){
int flow=0;
while(1){
queue<int> q;
memcpy(cur,head,sizeof(head));
memset(dis,-1,sizeof(dis));
dis[S]=0;
q.push(S);
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(dis[v]==-1&&e[i].lim){
dis[v]=dis[u]+1;
q.push(v);
}
}
}
if(dis[T]==-1) return flow;
flow+=dfs(S,1e9);
}
}
}G;
int main(){
n=read(),m=read();
S=1,T=2,tot=2;
for(int i=1;i<=n;++i){
a[i]=read();
if(!vis[a[i]]){
vis[a[i]]=1;
id_a[a[i]]=++tot;
G.add_edge(id_a[a[i]],T,m*a[i]*a[i]);
}
}
for(int i=1;i<=n;++i){
for(int j=i;j<=n;++j){
d[i][j]=read();
id[i][j]=++tot;
}
}
for(int i=1;i<=n;++i){
for(int j=i;j<=n;++j){
if(i==j) d[i][j]-=a[i];
if(d[i][j]>0){
G.add_edge(S,id[i][j],d[i][j]);
sum+=d[i][j];
}
else G.add_edge(id[i][j],T,-d[i][j]);
if(i==j) G.add_edge(id[i][j],id_a[a[i]],1e9);
else{
G.add_edge(id[i][j],id[i+1][j],1e9);
G.add_edge(id[i][j],id[i][j-1],1e9);
}
}
}
printf("%d\n",sum-G.max_flow());
return 0;
}
詳細信息
Test #1:
score: 5
Accepted
time: 1ms
memory: 4168kb
input:
2 0 11 10 20 12 40
output:
51
result:
ok single line: '51'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3896kb
input:
2 1 11 10 270 162 440
output:
630
result:
ok single line: '630'
Test #3:
score: 5
Accepted
time: 0ms
memory: 4096kb
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: 1ms
memory: 5860kb
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: 1ms
memory: 6040kb
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: 0ms
memory: 3864kb
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: 0ms
memory: 4032kb
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: 0ms
memory: 3816kb
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: 0ms
memory: 3788kb
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: 1ms
memory: 4044kb
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: 4152kb
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: 1ms
memory: 3944kb
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: 1ms
memory: 3896kb
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: 1ms
memory: 6140kb
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: 1ms
memory: 3900kb
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: 1ms
memory: 4232kb
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: 1ms
memory: 3948kb
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: 0ms
memory: 5984kb
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: 3ms
memory: 4556kb
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: 19ms
memory: 4268kb
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'