Go: package main

import "fmt"

func main() {
	//部屋を生成
	var H int

	fmt.Scan(&H)
	room := [][4]bool{}

	for i := 0; i < H; i++ {
		room = append(room, [4]bool{})
	}

	//荷物のおけない区画を設定
	var N int
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		room[y][x] = true //ものがある状態を真とする
	}
	//荷物を配置
	var count int
	for i := 0; i < 3; i++ {
		for j := 0; j < H-1; j++ {
			if !room[j][i] && !room[j+1][i] && !room[j][i+1] && !room[j+1][i+1] {
				room[j][i] = true
				room[j+1][i] = true
				room[j][i+1] = true
				room[j+1][i+1] = true
				count++
			}
		}
	}
	fmt.Println(count)
}

C++: #include<iostream>
#include<algorithm>
bool m[4][10010];
int dp[100010];
int main(){
	int H, N;
	std::cin >> H >> N;
	for(int i = 0; i < N; i++){
		int x, y;
		std::cin >> x >> y;
		m[x][y + 1] = true;
	}
	for(int i = 1; i < H; i++){
		dp[i] = std::max(dp[i], dp[i - 1]);
		int res1 = 0;
		if((!m[0][i]) && (!m[1][i]) && (!m[0][i + 1]) && (!m[1][i + 1]))res1++;
		if((!m[2][i]) && (!m[2][i]) && (!m[3][i + 1]) && (!m[3][i + 1]))res1++;
		int res2 = 0;
		if((!m[1][i]) && (!m[2][i]) && (!m[1][i + 1]) && (!m[2][i + 1]))res2++;
		dp[i] += std::max(res1, res2);
		dp[i + 2] = dp[i];		
	}
	std::cout << std::max(dp[H], dp[H - 1]) << std::endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int H,N;
int t[100005][4];
int dp[100005][1<<4];

int main(){
  cin>>H>>N;
  for(int i=0;i<N;i++){
    int x,y;
    cin>>x>>y;
    t[y][x]=1;
  }
  
  for(int i=0;i<H;i++)
    for(int j=0;j< (1<<4);j++)
      dp[i][j]=-100000000;
  
  dp[0][0]=0;
  int ans=0;
  
  for(int i=0;i<H;i++){
  
    for(int b=0;b<(1<<4);b++){
      
      ans=max(ans,dp[i][b]);
      if(i==H-1)continue;
      
      int tmp[2][4]={};
      
      for(int j=0;j<4;j++){
        tmp[0][j]=t[i][j];
        tmp[1][j]=t[i+1][j];
        tmp[0][j]|=(b>>j&1);
      }

      dp[i+1][0]=max(dp[i+1][0],dp[i][b]);
      
      if(!tmp[0][0]&&!tmp[0][1]&&!tmp[1][0]&&!tmp[1][1]){
        dp[i+1][3]=max(dp[i+1][3],dp[i][b]+1);
      }
      
      if(!tmp[0][1]&&!tmp[0][2]&&!tmp[1][1]&&!tmp[1][2]){
        dp[i+1][6]=max(dp[i+1][6],dp[i][b]+1);
      }
      
      if(!tmp[0][2]&&!tmp[0][3]&&!tmp[1][2]&&!tmp[1][3]){
        dp[i+1][12]=max(dp[i+1][12],dp[i][b]+1);
      }
      
      if(!tmp[0][0]&&!tmp[0][1]&&!tmp[1][0]&&!tmp[1][1]){
        if(!tmp[0][2]&&!tmp[0][3]&&!tmp[1][2]&&!tmp[1][3]){
          dp[i+1][15]=max(dp[i+1][15],dp[i][b]+2);
        }
      }
      
    }

    
  }

  cout<<ans<<endl;
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
using namespace std;
//
const int inf=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll a,ll b){
	return (b==0)?(a):(GCD(b,a%b));
}
ll LCM(ll a,ll b){
	return a/GCD(a,b)*b;
}
//
int H,N;
int ok[20000][4];
int DP[20000][5];
int main(){
	cin>>H>>N;
	FOR(i,0,H){
		FOR(j,0,4){
			ok[i][j]=1;
		}
	}
	FOR(i,0,N){
		int X,Y;
		cin>>X>>Y;
		ok[Y][X]=0;
	}
	/*
	cout<<endl;
	FOR(i,0,H){
		FOR(j,0,4){
			cout<<ok[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/
	//
	if(ok[0][0]&&ok[0][1]&&ok[1][0]&&ok[1][1]){
		DP[0][1]=1;
	}
	if(ok[0][1]&&ok[0][2]&&ok[1][1]&&ok[1][2]){
		DP[0][2]=1;
	}
	if(ok[0][2]&&ok[0][3]&&ok[1][2]&&ok[1][3]){
		DP[0][3]=1;
	}
	if(ok[0][0]&&ok[0][1]&&ok[1][0]&&ok[1][1]&&ok[0][2]&&ok[0][3]&&ok[1][2]&&ok[1][3]){
		DP[0][4]=2;
	}
	//
	if(ok[1][0]&&ok[1][1]&&ok[2][0]&&ok[2][1]){
		DP[1][1]=DP[0][3]+1;
	}
	if(ok[1][1]&&ok[1][2]&&ok[2][1]&&ok[2][2]){
		DP[1][2]=1;
	}
	if(ok[1][2]&&ok[1][3]&&ok[2][2]&&ok[2][3]){
		DP[1][3]=DP[0][1]+1;
	}
	if(ok[1][0]&&ok[1][1]&&ok[2][0]&&ok[2][1]&&ok[1][2]&&ok[1][3]&&ok[2][2]&&ok[2][3]){
		DP[1][4]=2;
	}
	//
	FOR(i,2,H-1){
		DP[i][0]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4]});
		DP[i][0]=max({DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		DP[i][1]=max({DP[i-1][3],DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4]});
		DP[i][2]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4]});
		DP[i][3]=max({DP[i-1][1],DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4]});
		DP[i][4]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4]});
		if(ok[i][0]&&ok[i][1]&&ok[i+1][0]&&ok[i+1][1]){
			DP[i][1]++;
		}else{
			DP[i][1]=max({DP[i][1],DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		}
		if(ok[i][1]&&ok[i][2]&&ok[i+1][1]&&ok[i+1][2]){
			DP[i][2]++;
		}else{
			DP[i][2]=max({DP[i][2],DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		}
		if(ok[i][2]&&ok[i][3]&&ok[i+1][2]&&ok[i+1][3]){
			DP[i][3]++;
		}else{
			DP[i][3]=max({DP[i][3],DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		}
		if(ok[i][0]&&ok[i][1]&&ok[i+1][0]&&ok[i+1][1]&&ok[i][2]&&ok[i][3]&&ok[i+1][2]&&ok[i+1][3]){
			DP[i][4]+=2;
		}else{
			DP[i][4]=max({DP[i][4],DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		}
	}
	int ans=0;
	/*
	FOR(i,0,H){
		FOR(j,0,5){
			cout<<DP[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/
	FOR(i,0,5){
		ans=max(ans,DP[H-2][i]);
	}
	cout<<ans<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int h;
int f[10000][4]={};

bool check(int bit, int shift)
{
    if(bit>>shift & 1) return false;
    if(bit>>(shift+1) & 1) return false;
    return true;
}

int dp[10000][1<<4];
int dfs(int y, int b)
{
    if(dp[y][b]>=0) return dp[y][b];
    if(y==h-1) return 0;

    int nx = 0;
    rep(i,4) nx |= f[y+1][i]<<i;
    int ret = 0;
    // 0???
    ret = max(ret, dfs(y+1,nx));
    // 1???
    rep(i,3)if(check(b,i) && check(nx,i))
    {
        int t = nx;
        t |= 1<<i;
        t |= 1<<(i+1);
        ret = max(ret, dfs(y+1,t)+1);
    }
    // 2???
    if(b==0 && nx==0) ret = max(ret, dfs(y+1,15)+2);

    return dp[y][b] = ret;
}

int main()
{
    int n;
    cin >>h >>n;
    rep(i,n)
    {
        int x,y;
        cin >>x >>y;
        f[y][x] = 1;
    }

    int s = 0;
    rep(i,4) s |= f[0][i]<<i;

    memset(dp,-1,sizeof(dp));
    cout << dfs(0,s) << endl;
    return 0;
}