Language: C++

// Filling Game

#include<iostream>
#include<vector>
#include<queue>
using namespace std;

typedef pair<int,int> Pos;
#define NONE -1

struct Data{
&#160; vector< vector<char> >panel;
&#160; int depth;
&#160; Data(){}
&#160; Data(vector< vector<char> >v, int n){panel=v;depth=n;}
};

int h,w;
char color[3]={'R','G','B'};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector< vector<char> > change(vector< vector<char> > panel, char after)
{
&#160; char pre=panel[1][1];
&#160; vector< vector<char> > visited(h+2,vector<char>(w+2,0));
&#160; queue<Pos> q;
&#160; q.push(Pos(1,1));
&#160; visited[1][1]=1;
&#160; while(!q.empty()){
&#160; &#160; Pos p=q.front();q.pop();
&#160; &#160; panel[p.first][p.second]=after;
&#160; &#160; for(int i=0;i<4;i++){
&#160; &#160; &#160; Pos next=p;
&#160; &#160; &#160; next.first+=dy[i];
&#160; &#160; &#160; next.second+=dx[i];
&#160; &#160; &#160; if(visited[next.first][next.second])continue;
&#160; &#160; &#160; if(panel[next.first][next.second]!=pre)continue;
&#160; &#160; &#160; q.push(next);
&#160; &#160; &#160; visited[next.first][next.second]=1;
&#160; &#160; }
&#160; }
&#160; return panel;
}

bool ok(vector< vector<char> > panel){
&#160; for(int i=0;i<h;i++){
&#160; &#160; for(int j=0;j<w;j++){
&#160; &#160; &#160; if(panel[i+1][j+1]!=panel[1][1])return false;
&#160; &#160; }
&#160; }
&#160; return true;
}

int solve(vector< vector<char> > panel)
{
&#160; int depth=0;
&#160; queue<Data>q;
&#160; q.push(Data(panel,0));
&#160; while(!q.empty()){
&#160; &#160; Data now=q.front();q.pop();
&#160; &#160; Data next;
&#160; &#160; next.depth=now.depth+1;
&#160; &#160; for(int c=0;c<3;c++){
&#160; &#160; &#160; if(now.panel[1][1]==color[c])continue;
&#160; &#160; &#160; next.panel=change(now.panel,color[c]);
&#160; &#160; &#160; if(ok(next.panel))return next.depth;
&#160; &#160; &#160; q.push(next);
&#160; &#160; }
&#160; }
&#160; return -1;
}

int main()
{
&#160; while(cin>>w>>h,w|h){
&#160; &#160; vector< vector<char> >panel(h+2,vector<char>(w+2,NONE));
&#160; &#160; for(int i=0;i<h;i++)for(int j=0;j<w;j++)scanf(" %1c", &panel[i+1][j+1]);

&#160; &#160; cout<<solve(panel)<<endl;
&#160; }
}

Compiler output:
a.cc:12:2: error: stray '#' in program
   12 | &#160; vector< vector<char> >panel;
      |  ^
a.cc:13:2: error: stray '#' in program
   13 | &#160; int depth;
      |  ^
a.cc:14:2: error: stray '#' in program
   14 | &#160; Data(){}
      |  ^
a.cc:15:2: error: stray '#' in program
   15 | &#160; Data(vector< vector<char> >v, int n){panel=v;depth=n;}
      |  ^
a.cc:25:2: error: stray '#' in program
   25 | &#160; char pre=panel[1][1];
      |  ^
a.cc:26:2: error: stray '#' in program
   26 | &#160; vector< vector<char> > visited(h+2,vector<char>(w+2,0));
      |  ^
a.cc:27:2: error: stray '#' in program
   27 | &#160; queue<Pos> q;
      |  ^
a.cc:28:2: error: stray '#' in program
   28 | &#160; q.push(Pos(1,1));
      |  ^
a.cc:29:2: error: stray '#' in program
   29 | &#160; visited[1][1]=1;
      |  ^
a.cc:30:2: error: stray '#' in program
   30 | &#160; while(!q.empty()){
      |  ^
a.cc:31:2: error: stray '#' in program
   31 | &#160; &#160; Pos p=q.front();q.pop();
      |  ^
a.cc:31:9: error: stray '#' in program
   31 | &#160; &#160; Pos p=q.front();q.pop();
      |         ^
a.cc:32:2: error: stray '#' in program
   32 | &#160; &#160; panel[p.first][p.second]=after;
      |  ^
a.cc:32:9: error: stray '#' in program
   32 | &#160; &#160; panel[p.first][p.second]=after;
      |         ^
a.cc:33:2: error: stray '#' in program
   33 | &#160; &#160; for(int i=0;i<4;i++){
      |  ^
a.cc:33:9: error: stray '#' in program
   33 | &#160; &#160; for(int i=0;i<4;i++){
      |         ^
a.cc:34:2: error: stray '#' in program
   34 | &#160; &#160; &#160; Pos next=p;
      |  ^
a.cc:34:9: error: stray '#' in program
   34 | &#160; &#160; &#160; Pos next=p;
      |         ^
a.cc:34:16: error: stray '#' in program
   34 | &#160; &#160; &#160; Pos next=p;
      |                ^
a.cc:35:2: error: stray '#' in program
   35 | &#160; &#160; &#160; next.first+=dy[i];
      |  ^
a.cc:35:9: error: stray '#' in program
   35 | &#160; &#160; &#160; next.first+=dy[i];
      |         ^
a.cc:35:16: error: stray '#' in program
   35 | &#160; &#160; &#160; next.first+=dy[i];
      |                ^
a.cc:36:2: error: stray '#' in program
   36 | &#160; &#160; &#160; next.second+=dx[i];
      |  ^
a.cc:36:9: error: stray '#' in program
   36 | &#160; &#160; &#160; next.second+=dx[i];
      |         ^
a.cc:36:16: error: stray '#' in program
   36 | &#160; &#160; &#160; next.second+=dx[i];
      |                ^
a.cc:37:2: error: stray '#' in program
   37 | &#160; &#160; &#160; if(visited[next.first][next.second])continue;
      |  ^
a.cc:37:9: error: stray '#' in program
   37 | &#160; &#160; &#160; if(visited[next.first][next.second])continue;
      |         ^
a.cc:37:16: error: stray '#' in program
   37 | &#160; &#160; &#160; if(visited[next.first][next.second])continue;
      |                ^
a.cc:38:2: error: stray '#' in program
   38 | &#160; &#160; &#160; if(panel[next.first][next.second]!=pre)continue;
      |  ^
a.cc:38:9: error: stray '#' in program
   38 | &#160; &#160; &#160; if(panel[next.first][next.second]!=pre)continue;
      |         ^
a.cc:38:16: error: stray '#' in program
   38 | &#160; &#160; &#160; if(panel[next.first][next.second]!=pre)continue;
      |                ^
a.cc:39:2: error: stray '#' in program
   39 | &#160; &#160; &#160; q.push(next);
      |  ^
a.cc:39:9: error: stray '#' in program
   39 | &#160; &#160; &#160; q.push(next);
      |         ^
a.cc:39:16: error: stray '#' in program
   39 | &#160; &#160; &#160; q.push(next);
      |                ^
a.cc:40:2: error: stray '#' in program
   40 | &#160; &#160; &#160; visited[next.first][next.second]=1;
      |  ^
a.cc:40:9: error: stray '#' in program
   40 | &#160; &#160; &#160; visited[next.first][next.second]=1;
      |         ^
a.cc:40:16: error: stray '#' in program
   40 | &#160; &#160; &#160; visited[next.first][next.second]=1;
      |                ^
a.cc:41:2: error: stray '#' in program
   41 | &#160; &#160; }
      |  ^
a.cc:41:9: error: stray '#' in program
   41 | &#160; &#160; }
      |         ^
a.cc:42:2: error: stray '#' in program
   42 | &#160; }
      |  ^
a.cc:43:2: error: stray '#' in program
   43 | &#160; return panel;
      |  ^
a.cc:47:2: error: stray '#' in program
   47 | &#160; for(int i=0;i<h;i++){
      |  ^
a.cc:48:2: error: stray '#' in program
   48 | &#160; &#160; for(int j=0;j<w;j++){
      |  ^
a.cc:48:9: error: stray '#' in program
   48 | &#160; &#160; for(int j=0;j<w;j++){
      |         ^
a.cc:49:2: error: stray '#' in program
   49 | &#160; &#160; &#160; if(panel[i+1][j+1]!=panel[1][1])return false;
      |  ^
a.cc:49:9: error: stray '#' in program
   49 | &#160; &#160; &#160; if(panel[i+1][j+1]!=panel[1][1])return false;
      |         ^
a.cc:49:16: error: stray '#' in program
   49 | &#160; &#160; &#160; if(panel[i+1][j+1]!=panel[1][1])return false;
      |                ^
a.cc:50:2: error: stray '#' in program
   50 | &#160; &#160; }
      |  ^
a.cc:50:9: error: stray '#' in program
   50 | &#160; &#160; }
      |         ^
a.cc:51:2: error: stray '#' in program
   51 | &#160; }
      |  ^
a.cc:52:2: error: stray '#' in program
   52 | &#160; return true;
      |  ^
a.cc:57:2: error: stray '#' in program
   57 | &#160; int depth=0;
      |  ^
a.cc:58:2: error: stray '#' in program
   58 | &#160; queue<Data>q;
      |  ^
a.cc:59:2: error: stray '#' in program
   59 | &#160; q.push(Data(panel,0));
      |  ^
a.cc:60:2: error: stray '#' in program
   60 | &#160; while(!q.empty()){
      |  ^
a.cc:61:2: error: stray '#' in program
   61 | &#160; &#160; Data now=q.front();q.pop();
      |  ^
a.cc:61:9: error: stray '#' in program
   61 | &#160; &#160; Data now=q.front();q.pop();
      |         ^
a.cc:62:2: error: stray '#' in program
   62 | &#160; &#160; Data next;
      |  ^
a.cc:62:9: error: stray '#' in program
   62 | &#160; &#160; Data next;
      |         ^
a.cc:63:2: error: stray '#' in program
   63 | &#160; &#160; next.depth=now.depth+1;
      |  ^
a.cc:63:9: error: stray '#' in program
   63 | &#160; &#160; next.depth=now.depth+1;
      |         ^
a.cc:64:2: error: stray '#' in program
   64 | &#160; &#160; for(int c=0;c<3;c++){
      |  ^
a.cc:64:9: error: stray '#' in program
   64 | &#160; &#160; for(int c=0;c<3;c++){
      |         ^
a.cc:65:2: error: stray '#' in program
   65 | &#160; &#160; &#160; if(now.panel[1][1]==color[c])continue;
      |  ^
a.cc:65:9: error: stray '#' in program
   65 | &#160; &#160; &#160; if(now.panel[1][1]==color[c])continue;
      |         ^
a.cc:65:16: error: stray '#' in program
   65 | &#160; &#160; &#160; if(now.panel[1][1]==color[c])continue;
      |                ^
a.cc:66:2: error: stray '#' in program
   66 | &#160; &#160; &#160; next.panel=change(now.panel,color[c]);
      |  ^
a.cc:66:9: error: stray '#' in program
   66 | &#160; &#160; &#160; next.panel=change(now.panel,color[c]);
      |         ^
a.cc:66:16: error: stray '#' in program
   66 | &#160; &#160; &#160; next.panel=change(now.panel,color[c]);
      |                ^
a.cc:67:2: error: stray '#' in program
   67 | &#160; &#160; &#160; if(ok(next.panel))return next.depth;
      |  ^
a.cc:67:9: error: stray '#' in program
   67 | &#160; &#160; &#160; if(ok(next.panel))return next.depth;
      |         ^
a.cc:67:16: error: stray '#' in program
   67 | &#160; &#160; &#160; if(ok(next.panel))return next.depth;
      |                ^
a.cc:68:2: error: stray '#' in program
   68 | &#160; &#160; &#160; q.push(next);
      |  ^
a.cc:68:9: error: stray '#' in program
   68 | &#160; &#160; &#160; q.push(next);
      |         ^
a.cc:68:16: error: stray '#' in program
   68 | &#160; &#160; &#160; q.push(next);
      |                ^
a.cc:69:2: error: stray '#' in program
   69 | &#160; &#160; }
      |  ^
a.cc:69:9: error: stray '#' in program
   69 | &#160; &#160; }
      |         ^
a.cc:70:2: error: stray '#' in program
   70 | &#160; }
      |  ^
a.cc:71:2: error: stray '#' in program
   71 | &#160; return -1;
      |  ^
a.cc:76:2: error: stray '#' in program
   76 | &#160; while(cin>>w>>h,w|h){
      |  ^
a.cc:77:2: error: stray '#' in program
   77 | &#160; &#160; vector< vector<char> >panel(h+2,vector<char>(w+2,NONE));
      |  ^
a.cc:77:9: error: stray '#' in program
   77 | &#160; &#160; vector< vector<char> >panel(h+2,vector<char>(w+2,NONE));
      |         ^
a.cc:78:2: error: stray '#' in program
   78 | &#160; &#160; for(int i=0;i<h;i++)for(int j=0;j<w;j++)scanf(" %1c", &panel[i+1][j+1]);
      |  ^
a.cc:78:9: error: stray '#' in program
   78 | &#160; &#160; for(int i=0;i<h;i++)for(int j=0;j<w;j++)scanf(" %1c", &panel[i+1][j+1]);
      |         ^
a.cc:80:2: error: stray '#' in program
   80 | &#160; &#160; cout<<solve(panel)<<endl;
      |  ^
a.cc:80:9: error: stray '#' in program
   80 | &#160; &#160; cout<<solve(panel)<<endl;
      |         ^
a.cc:81:2: error: stray '#' in program
   81 | &#160; }
      |  ^
a.cc:12:3: error: expected unqualified-id before numeric constant
   12 | &#160; vector< vector<char> >panel;
      |   ^~~
a.cc:13:3: error: expected unqualified-id before numeric constant
   13 | &#160; int depth;
      |   ^~~
a.cc:14:3: error: expected unqualified-id before numeric constant
   14 | &#160; Data(){}
      |   ^~~
a.cc:15:3: error: expected unqualified-id before numeric constant
   15 | &#160; Data(vector< vector<char> >v, int n){panel=v;depth=n;}
      |   ^~~
a.cc: In function 'std::vector<std::vector<char> > change(std::vector<std::vector<char> >, char)':
a.cc:25:3: error: lvalue required as unary '&' operand
   25 | &#160; char pre=panel[1][1];
      |   ^~~
a.cc:26:3: error: lvalue required as unary '&' operand
   26 | &#160; vector< vector<char> > visited(h+2,vector<char>(w+2,0));
      |   ^~~
a.cc:27:3: error: lvalue required as unary '&' operand
   27 | &#160; queue<Pos> q;
      |   ^~~
a.cc:28:3: error: lvalue required as unary '&' operand
   28 | &#160; q.push(Pos(1,1));
      |   ^~~
a.cc:29:3: error: lvalue required as unary '&' operand
   29 | &#160; visited[1][1]=1;
      |   ^~~
a.cc:30:3: error: lvalue required as unary '&' operand
   30 | &#160; while(!q.empty()){
      |   ^~~
a.cc:31:3: error: lvalue required as unary '&' operand
   31 | &#160; &