QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574761#9315. Rainbow Bracket SequenceCarucaoWA 1ms3844kbC++202.1kb2024-09-19 00:18:332024-09-19 00:18:34

Judging History

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

  • [2024-09-19 00:18:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3844kb
  • [2024-09-19 00:18:33]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=410;
const int inf=0x3f3f3f3f;
const int INF=1ll<<60;
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<<2];
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=-(mincost()-res);
	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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

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: 3844kb

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:

4210356253
343766215
2351080746
3426965219
1532026258
435918395
1351561190
2539318868
1013080942
4656646546
97527479
4197415484
2231197660
2719131728
3983627641
4712174168
998955757
1046749330
6115214757
3920988203
2853748600
3902088946
3209069508
2566553992
5268471900
5977120748
7505501534
38288708...

result:

wrong answer 1st numbers differ - expected: '-1', found: '4210356253'