QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#567432#9315. Rainbow Bracket Sequencejerry3128WA 1ms5876kbC++143.1kb2024-09-16 11:54:572024-09-16 11:54:57

Judging History

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

  • [2024-09-16 11:54:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5876kb
  • [2024-09-16 11:54:57]
  • 提交

answer

//ayanami±£ÓÓ£¬¿ä¸ç±£ÓÓ£¬¹·Âè±£ÓÓ£¬MDR±£ÓÓ£¬ï±µ¶¹Ö±£ÓÓ£¬M99±£ÓÓ£¬¿Ëµù±£ÓÓ
#include<bits/stdc++.h>
using namespace std;
int p1=1000000,p2=0;
char buf[1000005],wb[1000005];
int gc() {
	if(p1>=1000000)fread(buf,1,1000000,stdin),p1=0;
	return buf[p1++];
}
#define gc getchar
#define Loli true
#define Kon xor true
long long getint() {
	long long ret=0,flag=1;
	char c=gc();
	while(c<'0'||c>'9') {
		if(c=='-')flag=-1;
		c=gc();
	}
	while(c<='9'&&c>='0') {
		ret=(ret<<3)+(ret<<1)+c-'0';
		c=gc();
	}
	return ret*flag;
}
void pc(char x) {
	if(p2>=1000000)fwrite(wb,1,1000000,stdout),p2=0;
	wb[p2++]=x;
}
void wrt(long long x) {
	if(x<0)pc('-'),x=-x;
	int c[24]= {0};
	if(!x)return pc('0'),void();
	while(x)c[++c[0]]=x%10,x/=10;
	while(c[0])pc(c[c[0]--]+'0');
}
const int inf = 0x3f3f3f3f;
int n,m,l[105],c[205],v[205];
namespace G{
	const int S = 303,T = 304;
	const int SS = 301,TT = 302; 
	struct edge{int ne,v,p,c;}e[200005];
	int head[305],cnt=1,preflow[305],maxflow,maxcost,cost;
	vector<int> vec;
	void init(){cnt=1,memset(head,0,sizeof(head)),maxflow=0,maxcost=0,vec.clear();}
	void add_edge(int u,int v,int p,int c,int lim){
		++cnt,e[cnt]={head[u],v,p,c},head[u]=cnt;
		++cnt,e[cnt]={head[v],u,0,-c},head[v]=cnt;
		preflow[u]-=lim,preflow[v]+=lim;
	}
	void add_edge(int u,int v,int p,int c){
		++cnt,e[cnt]={head[u],v,p,c},head[u]=cnt;
		++cnt,e[cnt]={head[v],u,0,-c},head[v]=cnt;
	}
	void build(){
		for(int i=1;i<=(n<<1);i++){
			int cur=i;
			if(i>1)add_edge(cur,cur-1,n,0,0);
			if(cur&1)add_edge(SS,cur,0,0,1);
			add_edge(cur,(n<<1)+c[i],1,v[i],0);
		}
		for(int i=1;i<=m;i++){
			int cur=i+(n<<1);
			add_edge(cur,TT,n-l[i],0,l[i]);
		}
		add_edge(TT,SS,0,0,n);
		
		for(int i=1;i<=TT;i++){
			if(preflow[i]>0)add_edge(S,i, preflow[i],0),vec.push_back(cnt-1);
			if(preflow[i]<0)add_edge(i,T,-preflow[i],0),vec.push_back(cnt-1);
		}
	}
	bool SPFA(int pre[305]){
		static int dis[305];
		static bool vst[305];
		memset(dis,-0x3f,sizeof(dis));
		memset(vst,0,sizeof(vst));
		queue<int> q;
		dis[S]=0,q.push(S),vst[S]=1;
		while(!q.empty()){
			int u=q.front();q.pop();
			for(int i=head[u];i;i=e[i].ne){
				int v=e[i].v;
				if(e[i].p&&dis[v]<dis[u]+e[i].c){
					dis[v]=dis[u]+e[i].c,pre[v]=i;
					if(!vst[v])q.push(v),vst[v]=1;
				}
			}
			vst[u]=0;
		}
		return (cost=dis[T])>dis[0];
	}
	void adjust(int pre[305]){
		int p,dlt=inf;
		for(int i=T;i!=S;i=e[p^1].v)
			p=pre[i],dlt=min(dlt,e[p].p);
		for(int i=T;i!=S;i=e[p^1].v)
			p=pre[i],e[p].p-=dlt,e[p^1].p+=dlt;
		maxflow+=dlt;
		maxcost+=cost*dlt;
	}
	void solve(){
		static int pre[305]={0};
		while(SPFA(pre))adjust(pre);
	}
	bool check(){
		for(int i:vec)
			if(e[i].p)return false;
		return true;
	}
}
int main() {
	int Ti=getint();
	while(Ti--){
		n=getint(),m=getint(),G::init();
		for(int i=1;i<=m;i++)l[i]=getint();
		for(int i=1;i<=(n<<1);i++)c[i]=getint();
		for(int i=1;i<=(n<<1);i++)v[i]=getint();
		G::build(),G::solve(),wrt(G::check()?G::maxcost:-1),pc('\n');
	}
	fwrite(wb,1,p2,stdout);
	return Loli Kon;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5876kb

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

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'