fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define ldb long double
  4. #define fi first
  5. #define se second
  6. #define sza(a) (int)a.size()
  7. #define pir pair<int,int>
  8. #define pirll pair<ll,ll>
  9. using namespace std;
  10.  
  11. int a[5][5],arr[5][5],cnt[5][5];
  12.  
  13. bool is_equal(int n){
  14. for (int i = 1 ; i <= n ; i++)
  15. for (int j = 1 ; j <= n ; j++)
  16. if (a[i][j] != cnt[i][j]) return 0;
  17. return 1;
  18. }
  19.  
  20. int main(){
  21. ios_base::sync_with_stdio(false);
  22. cin.tie(0);cout.tie(0);
  23.  
  24. int n = 4,N = 16;
  25.  
  26. for (int i = 1 ; i <= n ; i++)
  27. for (int j = 1 ; j <= n ; j++) cin >> a[i][j];
  28.  
  29. for (int curmask = 0 ; curmask < (1 << N) ; curmask++){
  30. int mask = curmask;
  31.  
  32. for (int i = 1 ; i <= n ; i++){
  33. for (int bit = 0 ; bit < n ; bit++)
  34. arr[i][bit + 1] = (((1 << bit) & mask) > 0) ? 1 : 0;
  35.  
  36. mask >>= n;
  37. }
  38. memset(cnt,0,sizeof(cnt));
  39.  
  40. for (int i = 1 ; i <= n ; i++)
  41. for (int j = 1 ; j <= n ; j++)
  42. for (int x = -1 ; x <= 1 ; x++)
  43. for (int y = -1 ; y <= 1 ; y++)
  44. if (x != 0 || y != 0)
  45. cnt[i][j] += arr[i + x][j + y];
  46.  
  47. if (is_equal(n)){
  48. for (int i = 1 ; i <= n ; i++){
  49. for (int j = 1 ; j <= n ; j++) cout << arr[i][j] << " ";
  50. cout << "\n";
  51. }
  52. break;
  53. }
  54. }
  55.  
  56. return 0;
  57. }
  58.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
0 0 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0