QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#615162#9449. New School Termucup-team4938#WA 1ms7764kbC++143.0kb2024-10-05 17:44:442024-10-05 17:44:45

Judging History

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

  • [2024-10-05 17:44:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7764kb
  • [2024-10-05 17:44:44]
  • 提交

answer

#include<bits/stdc++.h>
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
using namespace std;
const int maxn=10010;
const int maxm=1000010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,m;
int f[maxn<<1],siz[maxn<<1];
pii a[maxm];
int fd(int x,bool fl=0){
	if(f[x]==x)return x;
	if(fl)return fd(f[x]);
	return f[x]=fd(f[x]);
}
bool vis[maxn];
int b[maxn],k,t[maxn<<1];
bitset<maxn/2> dp,g[maxn];
void work(){
	n=read()<<1;m=read();
	for(int i=1;i<=n*2;i++)f[i]=i,siz[i]=(i<=n);
	for(int i=1;i<=m;i++)a[i]={read(),read()};
	for(int i=m;i;i--){
		int u=a[i].fi,v=a[i].se;
		int uu=fd(u+n),vv=fd(v+n);u=fd(u),v=fd(v);
		if(u==v)continue;
		if(u==vv)continue;
		for(int j=0;j<=n;j++)t[j]=0;k=0;
		for(int j=1;j<=2*n;j++)f[j]=fd(j);
		siz[u]+=siz[vv],f[vv]=u;
		siz[v]+=siz[uu],f[uu]=v;
		for(int j=1;j<=n;j++)if(fd(j,1)==j&&fd(j+n,1)>j)t[abs(siz[j]-siz[fd(j+n,1)])]++;
		// for(int j=1;j<=n;j++)cout<<t[j]<<" ";cout<<"\n";
		for(int j=1;j<=n;j++)if(t[j]){
			for(int l=1;l<=t[j];l<<=1){
				b[++k]=j*l;
				t[j]-=l;
			}
			if(t[j])b[++k]=j*t[j];
		}
		sort(b+1,b+k+1);
		dp.reset();dp[0]=1;
		for(int j=1;j<=k;j++)dp=(dp<<b[j])|(dp>>b[j]);
		// cout<<k<<" ";for(int j=1;j<=k;j++)cout<<b[j]<<" ";cout<<"\n";
		if(!dp[0]){
			siz[u]-=siz[vv],f[vv]=vv;
			siz[v]-=siz[uu],f[uu]=uu;
			siz[u]+=siz[v],f[v]=u;
			if(uu<=n)siz[uu]+=siz[vv],f[vv]=uu;
			else siz[vv]+=siz[uu],f[uu]=vv;
		// if(i<=970483){
			// cout<<i<<" "<<u<<" "<<v<<" "<<uu<<" "<<vv<<"\n";
			// for(int j=1;j<=n;j++)if(fd(j)==j)cout<<j<<" "<<siz[j]<<"\n";
		// }
			// cout<<"0\n";
		}
		// cout<<i<<"\n";
		// for(int j=1;j<=n;j++)if(fd(j)==j)cout<<j<<" "<<siz[j]<<"\n";
	}
	// for(int i=1;i<=2*n;i++)if(fd(i)==i)cout<<fd(i)<<" "<<siz[fd(i)]<<"\n";
	g[0][0]=1;
	for(int i=1;i<=n;i++){
		if(fd(i)==i&&fd(i+n)>i){
			g[i]=(g[i-1]<<abs(siz[i]-siz[fd(i+n)]))|(g[i-1]>>abs(siz[i]-siz[fd(i+n)]));
		}
		else g[i]=g[i-1];
	}
	int x=0;
	for(int i=n;i;i--)if(fd(i)==i&&fd(i+n)>i){
		if(x>=abs(siz[i]-siz[fd(i+n)])&&g[i-1][x-abs(siz[i]-siz[fd(i+n)])]){
			x-=abs(siz[i]-siz[fd(i+n)]);
			if(siz[i]>=siz[fd(i+n)])vis[i]=1;
			else vis[fd(i+n)]=1;
		}
		else{
			x+=abs(siz[i]-siz[fd(i+n)]);
			if(siz[i]>siz[fd(i+n)])vis[fd(i+n)]=1;	
			else vis[i]=1;
		}
	}
	// for(int i=1;i<=n;i++)cout<<vis[i]<<" ";cout<<"\n";
	// int num=0;
	// for(int i=1;i<=n;i++){
		// if(vis[fd(i)])++num;
		// else --num;
	// }
	// cout<<num<<"\n";
	// if(num)return ;
	for(int i=1;i<=n;i++){
		if(vis[fd(i)])putchar('1');
		else putchar('0');
	}
	// puts("ac");
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
	// freopen("1.out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

详细

Test #1:

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

input:

2 4
1 3
2 4
1 4
1 2

output:

1010

result:

ok Output is valid. OK

Test #2:

score: 0
Accepted
time: 1ms
memory: 5764kb

input:

3 7
2 5
1 3
4 6
2 6
4 5
2 4
5 6

output:

100101

result:

ok Output is valid. OK

Test #3:

score: 0
Accepted
time: 1ms
memory: 5636kb

input:

1 0

output:

10

result:

ok Output is valid. OK

Test #4:

score: 0
Accepted
time: 1ms
memory: 5704kb

input:

1 1
1 2

output:

10

result:

ok Output is valid. OK

Test #5:

score: 0
Accepted
time: 1ms
memory: 5764kb

input:

2 3
2 4
3 4
1 2

output:

0110

result:

ok Output is valid. OK

Test #6:

score: 0
Accepted
time: 1ms
memory: 7764kb

input:

3 8
4 6
3 5
1 4
2 4
1 6
1 2
3 4
4 5

output:

101010

result:

ok Output is valid. OK

Test #7:

score: 0
Accepted
time: 1ms
memory: 5704kb

input:

4 9
4 7
3 8
1 5
2 7
2 8
6 8
7 8
1 4
1 6

output:

01010110

result:

ok Output is valid. OK

Test #8:

score: 0
Accepted
time: 1ms
memory: 5644kb

input:

5 16
3 6
9 10
2 7
1 10
1 5
2 10
3 5
5 6
3 4
2 5
4 5
3 8
4 7
6 8
1 6
7 10

output:

1101000101

result:

ok Output is valid. OK

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 5644kb

input:

6 13
4 5
2 9
3 8
4 8
4 11
10 12
3 4
3 9
5 11
2 8
5 10
5 8
1 11

output:

010101011100

result:

wrong answer The division is not minimized.