fork(1) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890123456789LL
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-8
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. #define dbl long double
  28. using namespace std;
  29. // mylittledoge
  30.  
  31. int main() {
  32. cin.sync_with_stdio(0);
  33. cin.tie(0);
  34. int T;
  35. cin >> T;
  36. for(int t =0; t < T; t++) {
  37. int N,M;
  38. cin >> N >> M;
  39. vector<string> A(N);
  40. vector<int> B(N);
  41. for(int i =0; i < N; i++) cin >> A[i] >> B[i];
  42. map<long long,long long> S;
  43. vector<long long> hsh(1<<(M/2));
  44. for(int a =0; a < (1<<(M/2)); a++) {
  45. long long x =0;
  46. bool ok =true;
  47. for(int i =0; i < N; i++) {
  48. int y =B[i];
  49. for(int j =0; j < M/2; j++)
  50. if((A[i][j] == '1') == ((a>>j)&1)) y--;
  51. if(y < 0) ok =false;
  52. x =x*(M+1)+y;}
  53. if(!ok) x =-1;
  54. hsh[a] =x;
  55. S[x] +=1;}
  56.  
  57. int ans =-1;
  58. long long ansP =0;
  59. for(int a =0; a < (1<<(M-M/2)); a++) {
  60. long long x =0;
  61. for(int i =0; i < N; i++) {
  62. int y =0;
  63. for(int j =M/2; j < M; j++)
  64. if((A[i][j] == '1') == ((a>>(j-M/2))&1)) y++;
  65. x =x*(M+1)+y;}
  66. ansP +=S[x];
  67. if(ans == -1 && S[x] > 0) {
  68. for(int i =0; i < (1<<(M/2)); i++)
  69. if(x == hsh[i]) ans =i+(1<<(M/2))*a;
  70. }
  71. }
  72.  
  73. if(ansP != 1) cout << ansP << " solutions";
  74. else for(int i =0; i < M; i++) cout << ((ans>>i)&1);
  75. cout << "\n";}
  76. return 0;}
  77.  
  78. // look at my code
  79. // my code is amazing
Success #stdin #stdout 0s 3480KB
stdin
3
3 5
01101 4
10100 3
00011 3
3 5
01101 0
10100 3
00011 2
4 4
0000 2
1010 2
0101 2
1111 2
stdout
00101
0 solutions
4 solutions