Language: C++

#include<iostream>
using namespace std;

int main(){
	int n,m,x[110][110],y[110][110],sum=0;
	memset(x,0,sizeof(x));
	cin>>m>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>x[i][j];
		}
	}
	memset(y,0,sizeof(y));
	for(int i=1;i<=m;i++){
		if(x[1][i]==0){
			y[1][i]=1;
			for(int j=1;j<100;j++){
				for(int k=1;k<=n;k++){
					for(int l=1;l<=m;l++){
						if(x[k][l]==0){
							if(x[k][l-1]==0){
								y[k][l-1]=1;
							}
							if(x[k-1][l]==0){
								y[k-1][l]=1;
							}
							if(k%2==0){
								if(x[k-1][l-1]==0){
									y[k-1][l-1]=1;
								}
								if(x[k+1][l-1]==0){
									y[k+1][l-1]=1;
								}
							}
							if(x[k][l+1]==0){
								y[k][l+1]=1;
							}
							if(x[k+1][l]==0){
								y[k+1][l]=1;
							}
							if(k%2==1){
								if(x[k+1][l+1]==0){
									y[k+1][l+1]=1;
								}
								if(x[k-1][l+1]==0){
									y[k-1][l+1]=1;
								}
							}
						}
					}
				}
				sum=0;
			}
		}
	}
	for(int i=1;i<=m;i++){
		if(x[n][i]==0){
			y[n][i]=1;
			for(int j=1;j<100;j++){
				for(int k=1;k<=n;k++){
					for(int l=1;l<=m;l++){
						if(x[k][l]==0){
							if(x[k][l-1]==0){
								y[k][l-1]=1;
							}
							if(x[k-1][l]==0){
								y[k-1][l]=1;
							}
							if(k%2==0){
								if(x[k-1][l-1]==0){
									y[k-1][l-1]=1;
								}
								if(x[k+1][l-1]==0){
									y[k+1][l-1]=1;
								}
							}
							if(x[k][l+1]==0){
								y[k][l+1]=1;
							}
							if(x[k+1][l]==0){
								y[k+1][l]=1;
							}
							if(k%2==1){
								if(x[k+1][l+1]==0){
									y[k+1][l+1]=1;
								}
								if(x[k-1][l+1]==0){
									y[k-1][l+1]=1;
								}
							}
						}
					}
				}
				sum=0;
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(x[i][1]==0){
			y[i][1]=1;
			for(int j=1;j<100;j++){
				for(int k=1;k<=n;k++){
					for(int l=1;l<=m;l++){
						if(x[k][l]==0){
							if(x[k][l-1]==0){
								y[k][l-1]=1;
							}
							if(x[k-1][l]==0){
								y[k-1][l]=1;
							}
							if(k%2==0){
								if(x[k-1][l-1]==0){
									y[k-1][l-1]=1;
								}
								if(x[k+1][l-1]==0){
									y[k+1][l-1]=1;
								}
							}
							if(x[k][l+1]==0){
								y[k][l+1]=1;
							}
							if(x[k+1][l]==0){
								y[k+1][l]=1;
							}
							if(k%2==1){
								if(x[k+1][l+1]==0){
									y[k+1][l+1]=1;
								}
								if(x[k-1][l+1]==0){
									y[k-1][l+1]=1;
								}
							}
						}
					}
				}
				sum=0;
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(x[i][m]==0){
			y[i][m]=1;
			for(int j=1;j<100;j++){
				for(int k=1;k<=n;k++){
					for(int l=1;l<=m;l++){
						if(x[k][l]==0){
							if(x[k][l-1]==0){
								y[k][l-1]=1;
							}
							if(x[k-1][l]==0){
								y[k-1][l]=1;
							}
							if(k%2==0){
								if(x[k-1][l-1]==0){
									y[k-1][l-1]=1;
								}
								if(x[k+1][l-1]==0){
									y[k+1][l-1]=1;
								}
							}
							if(x[k][l+1]==0){
								y[k][l+1]=1;
							}
							if(x[k+1][l]==0){
								y[k+1][l]=1;
							}
							if(k%2==1){
								if(x[k+1][l+1]==0){
									y[k+1][l+1]=1;
								}
								if(x[k-1][l+1]==0){
									y[k-1][l+1]=1;
								}
							}
						}
					}
				}
				sum=0;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(y[i][j]==0){
				x[i][j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(x[i][j]==1){
				if(x[i][j-1]==0){
					sum++;
				}
				if(x[i][j+1]==0){
					sum++;
				}
				if(x[i-1][j]==0){
					sum++;
				}
				if(x[i+1][j]==0){
					sum++;
				}
				if(i%2==0){
					if(x[i-1][j-1]==0){
						sum++;
					}
					if(x[i+1][j-1]==0){
						sum++;
					}
				}
				if(i%2==1){
					if(x[i-1][j+1]==0){
						sum++;
					}
					if(x[i+1][j+1]==0){
						sum++;
					}
				}
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:9: error: 'memset' was not declared in this scope
    6 |         memset(x,0,sizeof(x));
      |         ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    1 | #include<iostream>
  +++ |+#include <cstring>
    2 | using namespace std;