QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#218203 | #6552. Good and Lucky Matrices | zhouhuanyi | 0 | 0ms | 0kb | C++14 | 2.4kb | 2023-10-17 20:25:03 | 2023-10-17 20:25:04 |
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]);
}
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;
}
详细
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
11 11 2 11 11 01 10
Second Run Input
Second Run Output
result:
wrong answer Line element row[1] equals to "11", doesn't correspond to pattern "[01]{11}" (test case 1)