QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#878632 | #9692. Currency | ucup-team5177# | WA | 1ms | 5828kb | C++23 | 1.9kb | 2025-02-01 16:25:13 | 2025-02-01 16:25:15 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define INF2 100000000000000ll
#define INF 0x3f3f3f3f3f3f3f3f
#define f(x,y) ((x)*2+(y))
int S,T,N,M,a[509],c[509],b[509],hd[1009],to[100009],nxt[100009],val[100009],k=1,
d[1009],cur[1009];
inline bool bfs(void) {
std::queue<int> Q;
Q.push(S);
bool v[1009];
memset(v,0,sizeof(v));
v[S]=1;
while(!Q.empty()) {
int n=Q.front();Q.pop();
for(int i=hd[n];i;i=nxt[i])
if(!v[to[i]]&&val[i])
v[to[i]]=1,Q.push(to[i]),d[to[i]]=d[n]+1;
}
return v[T];
}
inline int dfs(int nod,int v) {
if((nod==T)||(v==0)) return v;
int flow=0,f;
for(int& i=cur[nod];i;i=nxt[i])
if(d[nod]+1==d[to[i]]&&(f=dfs(to[i],std::min(v,val[i])))) {
val[i]-=f;val[i^1]+=f;flow+=f;v-=f;
if(v==0) break;
}
if(!flow) d[nod]=-1;
return flow;
}
inline void set(void) {for(int i=1;i<=T;i++) cur[i]=hd[i];}
void l(int u,int v,int w) {
to[++k]=v;nxt[k]=hd[u];val[k]=w;hd[u]=k;
}
void co(int u,int v,int w) {
l(u,v,w),l(v,u,0);
}
signed main(void) {
scanf("%lld %lld",&N,&M);
S=1;T=2*N+2;
for(int i=1;i<N;i++) {
scanf("%lld",&a[i]);
}
for(int i=1;i<=N;i++) {
scanf("%lld",&c[i]);
}
for(int i=1;i<N;i++) {
scanf("%lld",&b[i]);
}
if(N==1) {
printf("%lld",c[1]);
return 0;
}
b[1]+=c[1];
a[N-1]+=c[N];
for(int i=1;i<N;i++) {
co(S,f(i,0),b[i]+INF2);
co(f(i,1),T,a[i]+INF2);
co(f(i,0),f(i,1),INF);
}
while(M--) {
int x,y,c;
scanf("%lld %lld %lld",&x,&y,&c);
co(f(x,0),f(y,1),c);
}
for(int i=1;i+1<N;i++) {
co(f(i,0),f(i+1,1),c[i+1]);
co(f(i,1),f(i+1,0),c[i+1]);
}
int ans=0;
while(bfs()) {
set();
ans+=dfs(S,INF);
}
printf("%lld",ans-INF2*(N-1));
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3968kb
input:
5 2 2 3 5 2 6 1 2 1 1 1 2 4 2 1 4 4 2 3 1
output:
13
result:
ok 1 number(s): "13"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3968kb
input:
6 1000 601450612 529194719 287622428 350370653 2490001 267842805 909540874 518481012 265798837 15815265 20879824 142543426 589509572 795333485 574202609 686307559 5 5 368241593 3 4 501344156 3 2 881313477 5 3 877155507 3 3 638857659 3 5 60427320 3 1 888140066 1 1 820913164 3 2 656494106 5 2 48265697...
output:
1792008237
result:
ok 1 number(s): "1792008237"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
6 1000 939223353 592232256 204123592 697949032 283207645 247227259 860831362 710972139 170824074 510978702 280845746 896873779 377774668 7308887 326686740 179453061 2 3 997446049 2 3 519323074 4 1 939589279 2 5 98041599 4 4 869921378 3 3 558765317 1 2 483873583 5 1 33483163 3 3 270388480 4 4 5510784...
output:
2035324394
result:
ok 1 number(s): "2035324394"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3968kb
input:
6 1000 959730384 933307890 88544023 434800479 519026844 598287106 88518137 220336188 475197957 997211224 13754116 615549399 359488030 322300660 426429747 456751804 2 1 37534981 2 1 826968454 4 5 736905082 2 2 392058437 3 2 148710959 5 3 340405411 4 3 756316407 1 1 989545410 1 4 953888522 1 2 4208087...
output:
2778806746
result:
ok 1 number(s): "2778806746"
Test #5:
score: 0
Accepted
time: 0ms
memory: 5828kb
input:
6 1000 828474485 450284805 615710614 642827608 358927789 340890875 324511822 431939488 283505035 960286257 744621984 19345807 677774542 254789794 431703631 752285873 4 1 619213429 4 2 475954933 2 1 372220764 4 3 365954206 5 2 66701266 5 5 715874448 2 1 385795225 2 4 215024198 2 3 335608279 4 5 81229...
output:
2476790522
result:
ok 1 number(s): "2476790522"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
6 1000 773101001 64230554 596335108 570954044 371802052 672297875 609818176 210924742 474129815 637532288 845662045 381562818 836547701 790875625 459034073 816120888 3 4 171273656 2 2 669511947 1 5 99209262 4 1 393105839 4 2 161297430 3 2 175654558 4 4 895979780 2 1 380318119 2 3 438246899 2 2 61661...
output:
3222084804
result:
ok 1 number(s): "3222084804"
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3968kb
input:
6 1000 786204681 325567741 53406367 432402436 442330564 1353889 4683275 528413577 555907196 568518211 61420817 117239404 703766279 710007531 852547435 543311026 1 1 830934334 2 3 981865567 3 2 439871419 3 2 377106611 1 1 849647504 2 4 590590318 5 5 333563280 3 4 908162812 1 3 384002897 4 4 701562502...
output:
1433721218
result:
wrong answer 1st numbers differ - expected: '1438404493', found: '1433721218'