Topic description:
QAQ.
Topic Analysis:
The observation coefficients are all 0 or 1.
This is called Gaussian elimination to solve the XOR equation.
Normal solution: a solution, the maximum number of rows visited is the answer, and then M[I][n+1] is the solution
No solution: that is, a row 1...n is all 0 but n+1 has a number (that is, 0x+0y+0z... = a non-zero number, which is obviously impossible), there is no such situation in this problem.
Countless solutions: that is, a row is all 0 (that is, 0x+0y+ 0z... = 0, obviously xyz can be taken arbitrarily)
The normal high consumption is O(N^3), which is theoretically impossible to passactually passed...
Considering that each elimination is the overall XOR of two lines, we can directly do a bitset optimization
O(N^2*m/64)
Topic link:
AC code:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <bitset>
const int maxm=2100;
std::bitset<maxm> a[maxm];
int n,m;
inline int Gauss()
{
int now=0,ans=0;
for(int i=1;i<=n;i++)
{
int j=now+1;
while(j<=m&&!a[j][i]) j++;
if(j>m) return -1;
ans=std::max(ans,j);
now++;
std::swap(a[now],a[j]);
for(int j=1;j<= m;j++)
if(j!=now&&a[j][i]) a[j]^=a[now];
}
return ans;
}
char s[maxm];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%s",s+1);
for(int j=1;j<=n;j++)
a[i][j]=s[j]-'0';
scanf("%s",s+1);
a[i][n+1]=s[1]-'0';
}
int d=Gauss();
if(~d)
{
printf("%d\n",d);
for(int i=1;i<=n;i++)
if(!a[i][n+1]) puts("Earth");
else puts("?y7M#");
}
else puts("Cannot Determine");
return 0;
}