Language: C++

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

typedef pair<int,int> P;

void solve(void);       //処理

int n;             //ブロックの個数
int w,h;           //ボードの幅、高さ
int goal;          //迷路になっているか
int scolor;        //スタート位置の色
int sx,sy,gx,gy;   //スタートの座標、ゴールの座標
int mass[SIZE][SIZE];
int data[SIZE][SIZE];
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){

    goal=0;

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

    if(w==0 && h==0)break;
    
    cin>>sx>>sy;
    cin>>gx>>gy;  
    cin>>n;
    
    for(i=0;i<n;i++){
      cin>>c[i]>>d[i]>>x[i]>>y[i];
      
    }

  memset(mass,0,sizeof(mass));

  /*マスの作成*/
  for(i=0;i<n;i++){
    if(d[i]==0){       //横向きなら
      for(j=0;j<4;j++){
	mass[y[i]][x[i]+j]=c[i];
	mass[y[i]+1][x[i]+j]=c[i];
      }
    }
    else if(d[i]==1){              //縦向きなら
      for(j=0;j<4;j++){
	mass[y[i]+j][x[i]]=c[i];
	mass[y[i]+j][x[i]+1]=c[i];
      }
    }
  }
  
  scolor=mass[sy][sx];

  if(scolor==mass[gy][gx]){
  
    solve();
     
    if(goal==1){
      cout<<"OK"<<endl;
    } else {
      cout<<"NG"<<endl;
      }
  }
  else {
    cout<<"NG"<<endl;
  }

  }
  
  return 0;
}
void solve(void){
  
  int i,j;
  queue<P> que;
  memset(data,-1,sizeof(data));
  que.push(P(sy,sx));     //queにスタート位置の座標を格納
  data[sy][sx]=0;
  
  while(!que.empty()){    //queが空でない間
    P p=que.front();
    que.pop();
    
    if(p.first==gy && p.second==gx){
      goal=1;
      break;
    }
    for(i=0;i<4;i++){
      int ny=p.first+dy[i];
      int nx=p.second+dx[i];
      if(nx>=0 && nx<w && ny>=0 && ny<h && mass[ny][nx]==scolor && data[ny][nx]==-1){
	que.push(P(ny,nx));
	data[ny][nx]=1;
      }
    }
  }
  return;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:3: error: 'memset' was not declared in this scope
   47 |   memset(mass,0,sizeof(mass));
      |   ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include<algorithm>
  +++ |+#include <cstring>
    6 | #define SIZE 110
a.cc: In function 'void solve()':
a.cc:89:10: error: reference to 'data' is ambiguous
   89 |   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:19:5: note:                 'int data [110][110]'
   19 | int data[SIZE][SIZE];
      |     ^~~~
a.cc:89:25: error: reference to 'data' is ambiguous
   89 |   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:19:5: note:                 'int data [110][110]'
   19 | int data[SIZE][SIZE];
      |     ^~~~
a.cc:89:3: error: 'memset' was not declared in this scope
   89 |   memset(data,-1,sizeof(data));
      |   ^~~~~~
a.cc:89:3: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:91:3: error: reference to 'data' is ambiguous
   91 |   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:19:5: note:                 'int data [110][110]'
   19 | int data[SIZE][SIZE];
      |     ^~~~
a.cc:104:68: error: reference to 'data' is ambiguous
  104 |       if(nx>=0 && nx<w && ny>=0 && ny<h && mass[ny][nx]==scolor && 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:19:5: note:                 'int data [110][110]'
   19 | int data[SIZE][SIZE];
      |     ^~~~
a.cc:106:9: error: reference to 'data' is ambiguous
  106 |         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:19:5: note:                 'int data [110][110]'
   19 | int data[SIZE][SIZE];
      |     ^~~~