Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define ll long long
#define loop(i,n) for (int i = 0; i < n; i++)
#define loops(i,f,n) for (int i = (f); i < n; i++)
#define INF 100000000000000
#define sort(a) sort(a.begin(),a.end())
#define rsort(a) sort(a.rbegin(),a.rend())
using namespace std;
int w, h, sx, sy, gx, gy, n;
vector <vector<int > > grid(105, vector<int>(105, 0));
vector <vector<bool > > grid_visited(105, vector<bool>(105, false));
void input(int c, int d, int x, int y)
{
	if (d == 0)//yokonaga
	{
		loop(i, 2)
		{
			loop(j, 4)
			{
				grid[y + i][x + j] = c;
			}
		}
	}
	else//tatenaga
	{
		loop(i, 4)
		{
			loop(j, 2)
			{
				grid[y + i][x + j] = c;
			}
		}
	}
}
bool a = false;
bool dfs(int nx, int ny)
{
	if (nx == gx&&ny == gy)return true;
	if (nx < 0 || ny < 0 || nx >= h || ny >= w || grid[nx][ny] == 0 || grid_visited[nx][ny])return false;
	grid_visited[nx][ny] = true;
	if ((nx + 1) >= 0 && ny >= 0 && (nx + 1) < h && ny < w)if (grid[nx + 1][ny] == grid[nx][ny])a |= dfs(nx + 1, ny);
	if (nx >= 0 && (ny + 1) >= 0 && nx < h && (ny + 1) < w)if (grid[nx][ny + 1] == grid[nx][ny])a |= dfs(nx, ny + 1);
	if ((nx - 1) >= 0 && ny >= 0 && (nx - 1) < h && ny < w)if (grid[nx - 1][ny] == grid[nx][ny])a |= dfs(nx - 1, ny);
	if (nx >= 0 && (ny - 1) >= 0 && nx < h && (ny - 1) < w)if (grid[nx][ny - 1] == grid[nx][ny])a |= dfs(nx, ny - 1);
	//return (dfs(nx + 1, ny) || dfs(nx, ny + 1) || dfs(nx - 1, ny) || dfs(nx, ny - 1));
	return a;
	return false;
}
int main()
{
	while (1)
	{
		cin >> w >> h;
		if (!w && !h) break;
		else
		{
			cin >> sx >> sy >> gx >> gy >> n;
			sx--; sy--; gx--; gy--;
			loop(i, n)
			{
				int c, d, x, y;
				cin >> c >> d >> x >> y;
				x--; y--;
				input(c, d, x, y);
			}
			/*loop(i, h)
			{
			loop(j, w)
			{
			cout << grid[i][j] << " ";
			}
			cout << endl;
			}*/
			grid = vector<vector<int> >(105, vector<int>(105, 0));
			grid_visited = vector <vector<bool > > (105, vector<bool>(105, false));
			a = false;

			cout << (dfs(sx, sy) ? "OK" : "NG") << endl;
		}
	}

}#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define ll long long
#define loop(i,n) for (int i = 0; i < n; i++)
#define loops(i,f,n) for (int i = (f); i < n; i++)
#define INF 100000000000000
#define sort(a) sort(a.begin(),a.end())
#define rsort(a) sort(a.rbegin(),a.rend())
using namespace std;
int w, h, sx, sy, gx, gy, n;
vector <vector<int > > grid(105, vector<int>(105, 0));
vector <vector<bool > > grid_visited(105, vector<bool>(105, false));
void input(int c, int d, int x, int y)
{
	if (d == 0)//yokonaga
	{
		loop(i, 2)
		{
			loop(j, 4)
			{
				grid[y + i][x + j] = c;
			}
		}
	}
	else//tatenaga
	{
		loop(i, 4)
		{
			loop(j, 2)
			{
				grid[y + i][x + j] = c;
			}
		}
	}
}
bool a = false;
bool dfs(int nx, int ny)
{
	if (nx == gx&&ny == gy)return true;
	if (nx < 0 || ny < 0 || nx >= h || ny >= w || grid[nx][ny] == 0 || grid_visited[nx][ny])return false;
	grid_visited[nx][ny] = true;
	if ((nx + 1) >= 0 && ny >= 0 && (nx + 1) < h && ny < w)if (grid[nx + 1][ny] == grid[nx][ny])a |= dfs(nx + 1, ny);
	if (nx >= 0 && (ny + 1) >= 0 && nx < h && (ny + 1) < w)if (grid[nx][ny + 1] == grid[nx][ny])a |= dfs(nx, ny + 1);
	if ((nx - 1) >= 0 && ny >= 0 && (nx - 1) < h && ny < w)if (grid[nx - 1][ny] == grid[nx][ny])a |= dfs(nx - 1, ny);
	if (nx >= 0 && (ny - 1) >= 0 && nx < h && (ny - 1) < w)if (grid[nx][ny - 1] == grid[nx][ny])a |= dfs(nx, ny - 1);
	//return (dfs(nx + 1, ny) || dfs(nx, ny + 1) || dfs(nx - 1, ny) || dfs(nx, ny - 1));
	return a;
	return false;
}
int main()
{
	while (1)
	{
		cin >> w >> h;
		if (!w && !h) break;
		else
		{
			cin >> sx >> sy >> gx >> gy >> n;
			sx--; sy--; gx--; gy--;
			loop(i, n)
			{
				int c, d, x, y;
				cin >> c >> d >> x >> y;
				x--; y--;
				input(c, d, x, y);
			}
			/*loop(i, h)
			{
			loop(j, w)
			{
			cout << grid[i][j] << " ";
			}
			cout << endl;
			}*/
			grid = vector<vector<int> >(105, vector<int>(105, 0));
			grid_visited = vector <vector<bool > > (105, vector<bool>(105, false));
			a = false;

			cout << (dfs(sx, sy) ? "OK" : "NG") << endl;
		}
	}

}


Compiler output:
a.cc:85:2: error: stray '#' in program
   85 | }#include<iostream>
      |  ^
a.cc:85:3: error: 'include' does not name a type
   85 | }#include<iostream>
      |   ^~~~~~~
a.cc:96:5: error: redefinition of 'int w'
   96 | int w, h, sx, sy, gx, gy, n;
      |     ^
a.cc:12:5: note: 'int w' previously declared here
   12 | int w, h, sx, sy, gx, gy, n;
      |     ^
a.cc:96:8: error: redefinition of 'int h'
   96 | int w, h, sx, sy, gx, gy, n;
      |        ^
a.cc:12:8: note: 'int h' previously declared here
   12 | int w, h, sx, sy, gx, gy, n;
      |        ^
a.cc:96:11: error: redefinition of 'int sx'
   96 | int w, h, sx, sy, gx, gy, n;
      |           ^~
a.cc:12:11: note: 'int sx' previously declared here
   12 | int w, h, sx, sy, gx, gy, n;
      |           ^~
a.cc:96:15: error: redefinition of 'int sy'
   96 | int w, h, sx, sy, gx, gy, n;
      |               ^~
a.cc:12:15: note: 'int sy' previously declared here
   12 | int w, h, sx, sy, gx, gy, n;
      |               ^~
a.cc:96:19: error: redefinition of 'int gx'
   96 | int w, h, sx, sy, gx, gy, n;
      |                   ^~
a.cc:12:19: note: 'int gx' previously declared here
   12 | int w, h, sx, sy, gx, gy, n;
      |                   ^~
a.cc:96:23: error: redefinition of 'int gy'
   96 | int w, h, sx, sy, gx, gy, n;
      |                       ^~
a.cc:12:23: note: 'int gy' previously declared here
   12 | int w, h, sx, sy, gx, gy, n;
      |                       ^~
a.cc:96:27: error: redefinition of 'int n'
   96 | int w, h, sx, sy, gx, gy, n;
      |                           ^
a.cc:12:27: note: 'int n' previously declared here
   12 | int w, h, sx, sy, gx, gy, n;
      |                           ^
a.cc:97:24: error: redefinition of 'std::vector<std::vector<int> > grid'
   97 | vector <vector<int > > grid(105, vector<int>(105, 0));
      |                        ^~~~
a.cc:13:24: note: 'std::vector<std::vector<int> > grid' previously declared here
   13 | vector <vector<int > > grid(105, vector<int>(105, 0));
      |                        ^~~~
a.cc:98:25: error: redefinition of 'std::vector<std::vector<bool> > grid_visited'
   98 | vector <vector<bool > > grid_visited(105, vector<bool>(105, false));
      |                         ^~~~~~~~~~~~
a.cc:14:25: note: 'std::vector<std::vector<bool> > grid_visited' previously declared here
   14 | vector <vector<bool > > grid_visited(105, vector<bool>(105, false));
      |                         ^~~~~~~~~~~~
a.cc:99:6: error: redefinition of 'void input(int, int, int, int)'
   99 | void input(int c, int d, int x, int y)
      |      ^~~~~
a.cc:15:6: note: 'void input(int, int, int, int)' previously defined here
   15 | void input(int c, int d, int x, int y)
      |      ^~~~~
a.cc:122:6: error: redefinition of 'bool a'
  122 | bool a = false;
      |      ^
a.cc:38:6: note: 'bool a' previously defined here
   38 | bool a = false;
      |      ^
a.cc:123:6: error: redefinition of 'bool dfs(int, int)'
  123 | bool dfs(int nx, int ny)
      |      ^~~
a.cc:39:6: note: 'bool dfs(int, int)' previously defined here
   39 | bool dfs(int nx, int ny)
      |      ^~~
a.cc:136:5: error: redefinition of 'int main()'
  136 | int main()
      |     ^~~~
a.cc:52:5: note: 'int main()' previously defined here
   52 | int main()
      |     ^~~~