Language: C++

#include<map>
#include<queue>
#include<cstdio>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define SIZE 102
using namespace std;

typedef pair<int,int> P;

void input_data(void);  //データ入力用関数
void make_mass(void);   //マス作成用関数
void solve(void);       //処理
void clear(void);       //データの初期化

int n;             //ブロックの個数
int w,h;           //ボードの幅、高さ
int goal=0;
int sx,sy,gx,gy;   //スタートの座標、ゴールの座標
int mass[102][102];
int data[102][102];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int c[SIZE],d[SIZE],x[SIZE],y[SIZE];       //ブロックの色、向き、左上の座標


int main(){

  int i,j;             //カウンタ変数

  while(1){

    /*情報の入力*/
    cin>>w>>h;

    if(w==h && w==0)break; //ループ終了条件

    input_data();

    make_mass();

    solve();

    /*printf("%d\n",goal);*/

    if(goal==1){
      cout<<"OK"<<endl;
    } else {
      cout<<"NG"<<endl;
      }

    /*    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	printf("%2d",data[i][j]);
      }
      printf("     ");
      for(j=0;j<w;j++){
	printf("%2d",mass[i][j]);
      }
      printf("\n");
      }                          */
    clear();

  }

  return 0;
}
void input_data(void){

    cin>>sx>>sy;
    cin>>gx>>gy;

    cin>>n;

    for(int i=0;i<n;i++){
      cin>>c[i]>>d[i]>>x[i]>>y[i];

    }

    return;
}
void make_mass(void){

  int i,j;
  int scolor,fcolor;

    /*マスの作成*/
    for(i=0;i<n;i++){
	switch(d[i]){
	case 0:              //横向きなら
	  for(j=0;j<4;j++){
	    mass[y[i]][x[i]+j]=c[i];
	    mass[y[i]+1][x[i]+j]=c[i];
	  }
	  break;
	case 1:              //縦向きなら
	  for(j=0;j<4;j++){
	    mass[y[i]+j][x[i]]=c[i];
	    mass[y[i]+j][x[i]+1]=c[i];
	  }
	  break;
	}
      }

    scolor=mass[sy][sx];
    fcolor=mass[gy][gx];

      for(i=0;i<h;i++){
	for(j=0;j<w;j++){
	  if(scolor!=mass[i][j]){
	    mass[i][j]=0;
	  }
	}
      }

    return;
}
void solve(void){

  int i,j;
  queue<P> que;
  memset(data,-1,sizeof(data));
  que.push(P(sx,sy));     //queにスタート位置の座標を格納
  data[sy][sx]==0;

  while(!que.empty()){    //queが空でない間
    P p=que.front();
    que.pop();

    if(p.first==gx && p.second==gy){
      goal=1;
      /* cout<<" (^q^)くおえうえーーーるえうおおおwwww"<<endl;*/
      break;
    }
    for(i=0;i<4;i++){
      int nx=p.first+dx[i];
      int ny=p.second+dy[i];
      if(nx>=0 && nx<w && ny>=0 && ny<h && mass[ny][nx]!=0 && data[ny][nx]==-1){
	que.push(P(nx,ny));
	data[ny][nx]=data[p.second][p.first]+1;
      }
    }
  }
  return;
}


void clear(void){

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      mass[i][j]==0;
    }
  }
  goal=0;

  return;
}
/*
花火は他人に向けちゃダメだよ。

( ・ω・)o─━・*:・:・(※)`Д´)アヂィ!

*/

Compiler output:
a.cc: In function 'void solve()':
a.cc:123:10: error: reference to 'data' is ambiguous
  123 |   memset(data,-1,sizeof(data));
      |          ^~~~
In file included from /usr/include/c++/14/map:65,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:5: note:                 'int data [102][102]'
   22 | int data[102][102];
      |     ^~~~
a.cc:123:25: error: reference to 'data' is ambiguous
  123 |   memset(data,-1,sizeof(data));
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:5: note:                 'int data [102][102]'
   22 | int data[102][102];
      |     ^~~~
a.cc:123:3: error: 'memset' was not declared in this scope
  123 |   memset(data,-1,sizeof(data));
      |   ^~~~~~
a.cc:7:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    6 | #include<algorithm>
  +++ |+#include <cstring>
    7 | #define SIZE 102
a.cc:125:3: error: reference to 'data' is ambiguous
  125 |   data[sy][sx]==0;
      |   ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:5: note:                 'int data [102][102]'
   22 | int data[102][102];
      |     ^~~~
a.cc:139:63: error: reference to 'data' is ambiguous
  139 |       if(nx>=0 && nx<w && ny>=0 && ny<h && mass[ny][nx]!=0 && data[ny][nx]==-1){
      |                                                               ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:5: note:                 'int data [102][102]'
   22 | int data[102][102];
      |     ^~~~
a.cc:141:9: error: reference to 'data' is ambiguous
  141 |         data[ny][nx]=data[p.second][p.first]+1;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:5: note:                 'int data [102][102]'
   22 | int data[102][102];
      |     ^~~~
a.cc:141:22: error: reference to 'data' is ambiguous
  141 |         data[ny][nx]=data[p.second][p.first]+1;
      |                      ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:5: note:                 'int data [102][102]'
   22 | int data[102][102];
      |     ^~~~