どこが間違っているのでしょうか?
問題ページ
↓コード
#include <iostream>
using namespace std;
void SET(int c,int d,int x,int y,int few[105][105]){
if(d==1){
few[y][x] =few[y+1][x] =few[y+2][x] =few[y+3][x] =c;
few[y][x+1]=few[y+1][x+1]=few[y+2][x+1]=few[y+3][x+1]=c;
}else if(d==0){
few[y][x] =few[y][x+1] =few[y][x+2] =few[y][x+3] =c;
few[y+1][x]=few[y+1][x+1]=few[y+1][x+2]=few[y+1][x+3]=c;
}
}
bool e=false;
bool SAT(int c,int y,int x,int yg,int xg,int few[105][105]){
if(e)return true;
if(y==yg&&x==xg){ e=true; return true;}
if(few[y][x+1]==c) SAT(c,y,x+1,yg,xg,few);
if(few[y+1][x]==c) SAT(c,y+1,x,yg,xg,few);
if(few[y][x-1]==c) SAT(c,y,x-1,yg,xg,few);
if(few[y-1][x]==c) SAT(c,y+1,x,yg,xg,few);
if(e)return true;
return false;
}
int main(){
int w, h, xs, ys, xg, yg, n;
int c, d, x, y;
while(cin>>w>>h){
if(w==0&&h==0) return NULL;
int few[105][105]={0,};
cin>>xs>>ys>>xg>>yg>>n;
for(int i=1;i<=n;i++){
cin>>c>>d>>x>>y;
SET(c,d,x,y,few);
}
if(few[ys][xs]!=few[yg][xg]) cout<<"NG"<<endl;
else{
e=false;
if(SAT(few[ys][xs],ys,xs,yg,xg,few)) cout<<"OK"<<endl;
else cout<<"NG"<<endl;
}
}
return NULL;
}