QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574784#9315. Rainbow Bracket SequenceCarucaoCompile Error//C++202.0kb2024-09-19 00:32:542024-09-19 00:32:58

Judging History

你现在查看的是最新测评结果

  • [2024-09-19 00:32:58]
  • 评测
  • [2024-09-19 00:32:54]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=410;
const int inf=0x3f3f3f3f;
int n,m,l[N],col[N],v[N],dis[N],num,head[N],pre[N],s,t,preve[N];
bool p[N];
queue<int> q;
struct adc
{
	int nex,to,cost,z;
}c[N<<4];
void ljb(int x,int y,int cost,int z)
{
	c[++num].nex=head[x];
	c[num].to=y;
	c[num].cost=cost;
	c[num].z=z;
	head[x]=num;
}
void add(int x,int y,int cost,int z)
{
	ljb(x,y,cost,z);
	ljb(y,x,-cost,0);
}
bool spfa()
{
	for(int i=1;i<=t;++i) pre[i]=0,dis[i]=inf,p[i]=0;
	dis[s]=0;
	q.push(s);
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		p[x]=0;
		for(int i=head[x];i;i=c[i].nex)
		{
			if(c[i].z>0)
			{
				int y=c[i].to,cost=c[i].cost;
				if(dis[x]+cost<dis[y])
				{
					dis[y]=dis[x]+cost;
					pre[y]=x;
					preve[y]=i;
					if(!p[y])
					{
						p[y]=1;
						q.push(y);
					}
				}
			}
		}
	}
	return dis[t]!=INF;
}
int mincost()
{
	int cost=0;
	while(spfa())
	{
		int v=t,flow=inf;
		while(pre[v])
		{
			int u=pre[v],i=preve[v];
			flow=min(flow,c[i].z);
			v=u;
		}
		v=t;
		while(pre[v])
		{
			int u=pre[v],i=preve[v];
			c[i].z-=flow;
			c[i^1].z+=flow;
			v=u;
		}
		cost+=dis[t]*flow;
	}
	return cost;
}
void work()
{
    cin>>n>>m;
    num=1;
    for(int i=1;i<=2*n+m+2;++i) head[i]=0;
    int res=0;
    for(int i=1;i<2*n;++i)
    {
    	add(i,i+1,-inf,(i+1)/2);
    	add(i,i+1,0,n);
    	res+=(i+1)/2*(-inf);
	}
	s=2*n+m+1,t=2*n+m+2;
	add(2*n,t,0,n);
	int sum=0;
	for(int i=1;i<=m;++i)
	{
		cin>>l[i];
		sum+=l[i];
		add(s,2*n+i,-inf,l[i]);
		add(s,2*n+i,0,n);
		res+=l[i]*(-inf);
	}
	for(int i=1;i<=2*n;++i) cin>>col[i];
	for(int i=1;i<=2*n;++i)
	{
		cin>>v[i];
		add(2*n+col[i],i,-v[i],1);
	}
	if(sum>n)
	{
		cout<<-1<<endl;
		return;
	}
	int ans=res-mincost();
	if(ans<0) cout<<-1<<endl;
	else cout<<ans<<endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T=1;
    cin>>T;
    for(;T;--T)
      work();
    return 0;
}

Details

answer.code: In function ‘bool spfa()’:
answer.code:56:24: error: ‘INF’ was not declared in this scope
   56 |         return dis[t]!=INF;
      |                        ^~~