QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#218205#6552. Good and Lucky Matriceszhouhuanyi0 0ms0kbC++142.4kb2023-10-17 20:25:262023-10-17 20:25:27

Judging History

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

  • [2023-10-17 20:25:27]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-10-17 20:25:26]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<bitset>
#define N 2000
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int T,n,num[N+1],tong[N+1],length,tong2[N+1],length2;
bitset<N+1>B[N+1];
bitset<N+1>B2[N+1];
bitset<N+1>c[N+1];
bool used[N+1],vis[N+1];
void insert(bitset<N+1>st)
{
	for (int i=n;i>=1;--i)
		if (st[i])
		{
			if (!c[i][i])
			{
				c[i]=st;
				return;
			}
			else st^=c[i];
		}
	return;
}
void solve(bitset<N+1>st)
{
	for (int i=n;i>=1;--i)
		if (st[i])
		{
			vis[i]=1;
			if (!c[i][i]) st[i]=0;
			else st^=c[i];
		}
	return;
}
int main()
{
	string s;
	int ps,ps2;
	char cs;
	T=read();
	while (T--)
	{
		cin>>s,n=read();
		for (int i=1;i<=n;++i)
		{
			for (int j=1;j<=n;++j) cin>>cs,B[i][j]=cs-'0';
			B2[i].reset(),c[i].reset();
		}
		if (s=="lucky")
		{
			for (int i=1;i<=n;++i) used[i]=0;
			for (int i=1;i<=n;++i)
			{
				length=length2=ps=ps2=0;
				for (int j=1;j<=n;++j)
				{
					if (c[j][j]) tong[++length]=j;
					else tong2[++length2]=j;
				}
				for (int j=1;j<=n;++j)
				{
					if (used[j])
					{
						++ps;
						if (B[i][j]) B2[i]^=c[tong[ps]];
					}
					else
					{
						++ps2;
						if (B[i][j]) B2[i][tong2[ps2]]=1;
					}
				}
				for (int j=1;j<=n;++j)
					if (B[i][j]&&!used[j])
					{
						used[j]=1;
						break;
					}
				insert(B2[i]);
			}
			printf("%d\n",n);
			for (int i=1;i<=n;++i)
			{
				for (int j=1;j<=n;++j) printf("%d",(int)(B2[i][j]));
				puts("");
			}
		}
		else
		{
			for (int i=1;i<=n;++i) used[i]=0;
			for (int i=1;i<=n;++i)
			{
				length=length2=ps=ps2=0;
				for (int j=1;j<=n;++j) vis[j]=0;
				for (int j=1;j<=n;++j)
				{
					if (used[j]) tong[++length]=j;
					else tong2[++length2]=j;
				}
				for (int j=1;j<=n;++j)
				{
					if (c[j][j]) num[j]=++ps;
					else num[j]=++ps2;
				}
				solve(B[i]);
				for (int j=1;j<=n;++j)
					if (vis[j])
					{
						if (c[j][j]) B2[i][tong[num[j]]]=1;
						else B2[i][tong2[num[j]]]=1;
					}
				for (int j=1;j<=n;++j)
					if (B2[i][j]&&!used[j])
					{
						used[j]=1;
						break;
					}
				insert(B[i]);
			}
			printf("%d\n",n);
			for (int i=1;i<=n;++i)
			{
				for (int j=1;j<=n;++j) printf("%d",(int)(B2[i][j]));
				puts("");
			}
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer on the first run

First Run Input

3
lucky
2
11
11
good
2
11
01
lucky
2
01
10

First Run Output

2
11
11
2
11
11
2
01
10

Second Run Input


Second Run Output


result:

wrong answer Matrix should be good (test case 1)