QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#574561 | #9315. Rainbow Bracket Sequence | qlwpc | WA | 1ms | 3856kb | C++14 | 2.3kb | 2024-09-18 22:46:27 | 2024-09-18 22:46:28 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<iostream>
const int M = 2020;
const int N = 550;
using ll = long long;
const ll INF = 0x3f3f3f3f3f3f3f3f;
struct node{
int fr,to,next,res,dis;
}q[M];
int head[N],ss,S,T,lst[N],que[N<<2],flow[N];
ll dis[N],minc,maxf;bool inq[N];
void addedge(int x,int y,int v,int f)
{
q[++ss]=(node){x,y,head[x],f, v};head[x]=ss;
q[++ss]=(node){y,x,head[y],0,-v};head[y]=ss;
}
bool spfa()
{
memset(flow,0x3f,sizeof(flow));
memset(dis,0x3f,sizeof(dis));
int f=1,e=0;
dis[S]=0;
que[++e]=S;
while(f<=e)
{
int u=que[f++];inq[u]=false;
for (int j=head[u];~j;j=q[j].next)
{
int t=q[j].to;
if (q[j].res&&dis[t]>dis[u]+q[j].dis)
{
dis[t]=dis[u]+q[j].dis;
flow[t]=std::min(flow[u],q[j].res);
lst[t]=j;
if (!inq[t]) que[++e]=t,inq[t]=true;
}
}
}
return dis[T]!=INF;
}
void mcmf()
{
while(spfa())
{
minc += flow[T]*dis[T];
maxf += flow[T];
for (int i=T;i!=S;i=q[lst[i]].fr)
{
int j=lst[i];
q[j].res-=flow[T];
q[j^1].res+=flow[T];
}
}
}
int l[N],c[N],v[N],cnt[N];
int main()
{
memset(head,-1,sizeof(head));ss=-1;
int TT;
scanf("%d",&TT);
while(TT--)
{
int n,m;
scanf("%d%d",&n,&m);
for (int i=1;i<=m;++i) scanf("%d",&l[i]);
for (int i=1;i<=2*n;++i) scanf("%d",&c[i]);
for (int i=1;i<=2*n;++i) scanf("%d",&v[i]);
for (int i=1;i<=2*n;++i) cnt[c[i]]++;
S=0;
for (int i=1;i<=m;++i) addedge(S,i,0,cnt[i]-l[i]);
for (int j=1;j<=2*n;++j)
addedge(c[j], m+j, v[j], 1);
for (int i=1;i<=2*n;++i)
addedge(m+i, m+i+2*n, 0, 1);
for (int i=2;i<=2*n;++i)
addedge(m+2*n+i, m+2*n+i+1, 0, i/2);
T = m+2*n+2*n+1;
ll tot = 0;
for (int i=1;i<=2*n;++i) tot += v[i];
mcmf();
if (maxf!=n) printf("-1\n");
else
printf("%lld\n",tot-minc);
for (int i=S;i<=T;++i) head[i]=-1;
for (int i=1;i<=m;++i) cnt[i]=0;
ss=-1;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3856kb
input:
2 3 2 1 2 1 2 2 2 1 2 3 1 4 2 2 1 3 2 2 2 1 2 2 2 1 2 3 1 4 2 2 1
output:
9 -1
result:
ok 2 number(s): "9 -1"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3804kb
input:
50 8 6 0 2 2 0 3 1 3 5 1 1 5 3 5 2 3 2 2 1 2 2 4 6 998133227 879226371 59632864 356493387 62611196 827258251 296576565 204244054 812713672 780267148 614679390 447700005 102067050 544546349 116002772 761999375 1 1 1 1 1 343766215 374461155 3 1 2 1 1 1 1 1 1 796323508 303640854 701432076 853325162 610...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
wrong answer 2nd numbers differ - expected: '343766215', found: '-1'