fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define is(X) cout<<#X<<" is "<<X<<endl
  4. #define ll long long
  5. int n,M[12][100003];
  6. const int MOD=1e9+7;
  7. ll int power(ll int a,ll int b)
  8. {
  9. ll int ans=1;
  10. while(b)
  11. {
  12. if(b&1)ans=(ans%MOD * a%MOD)%MOD;
  13. a*=a;
  14. b/=2;
  15. }
  16. return ans%MOD;
  17. }
  18. bool check(int i)
  19. {
  20. for(int j=0;j<=n-1;j++)
  21. {
  22. //we want all these columns to be 0
  23. if(M[i][j]==1)return false;
  24. }
  25. //last column should be 1
  26. if(M[i][n]==0)return false;
  27. return true;
  28. }
  29. ll int answer()
  30. {
  31. //gaussian elimination
  32. int last=-1;
  33. int x = 10,m = n+1;
  34. //is(x);is(m);
  35. for(int i=0;i<x;++i)
  36. {
  37. for(int j=0;j<m-1;++j)
  38. {
  39. if(M[i][j])
  40. {
  41. last = j;
  42. for(int k=0;k<x;++k)
  43. {
  44. if(k==i)continue;
  45. if(M[k][j])
  46. {
  47. for(int t=0;t<m;++t)
  48. {
  49. M[k][t] ^= M[i][t];
  50. }
  51. }
  52. }
  53. break;
  54. }
  55. }
  56. }
  57. //check for inconsistent matrix
  58. for(int i=0;i<10;++i)
  59. {
  60. if(check(i))return 0;
  61. }
  62. return power(2,(n-1-last));
  63. }
  64. int main()
  65. {
  66. //freopen("input.txt","r",stdin);
  67. int t;
  68. scanf("%d",&t);
  69. while(t--)
  70. {
  71. char image[13];
  72. scanf("%s",image);
  73. scanf("%d",&n);
  74. for(int i=0;i<10;++i){M[i][n]=(image[i]=='w')?1:0;}
  75. for(int i=0;i<n;i++)
  76. {
  77. char temp[15];
  78. scanf("%s",temp);
  79. for(int j=0;j<10;++j)
  80. M[j][i] = (temp[j]=='+')?1:0;
  81. }
  82. /*for(int i=0;i<10;++i)
  83.   {
  84.   for(int j=0;j<4;++j)
  85.   cout<<M[i][j]<<" ";
  86.   cout<<endl;
  87.   }*/
  88. printf("%d\n",answer());
  89. }
  90. }
  91.  
Success #stdin #stdout 0s 8152KB
stdin
3
wwwwwwwwww
3
+-+-+-+-+-
----------
+---------
wbwbwbwbwb
3
+-+-+-+-+-
+-+-------
----+-+-+-
bbbbbbbbbb
2
----------
----------
stdout
0
2
4