#pragma GCC optimize ("Ofast") #include using namespace std; inline int my_getchar(){ return getchar(); } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(char &c){ int i; for(;;){ i = my_getchar(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c = i; } inline int rd(char c[]){ int i; int sz = 0; for(;;){ i = my_getchar(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = my_getchar(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } inline void my_putchar(const int k){ putchar(k); if(k=='\n'){ fflush(stdout); } } inline void wt_L(char a){ my_putchar(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar('-'); } while(s--){ my_putchar(f[s]+'0'); } } inline void wt_L(const char c[]){ int i=0; for(i=0;c[i]!='\0';i++){ my_putchar(c[i]); } } int x[1000000]; int y[1000000]; int qsz; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, 1, -1}; int path[510][1100]; int N; int M; bool within(int a, int b){ return (0 <= a && a < N) && ( 0 <= b && b < N); } char res[100]; int counts = 0; int ask(int a, int b){ if(path[a][b] != -1){ return path[a][b]; } ++counts; if(counts > 3000){ return -1; } wt_L(a+1); wt_L(' '); wt_L(b+1); wt_L('\n'); rd(res); if(res[0] == 'B'){ path[a][b] = 0; } if(res[0] == 'W'){ path[a][b] = 1; } return path[a][b]; } int main(){ int i; memset(path, 0xff, sizeof(path)); rd(N); rd(M); x[0] = 0; y[0] = 0; qsz = 1; bool ended = false; path[0][0] = 0; for(i=(0);i<(qsz);i++){ int j; for(j=(0);j<(4);j++){ int nx = x[i] + dx[j]; int ny = y[i] + dy[j]; if(path[nx][ny] != -1){ continue; } if(!within(nx, ny)){ continue; } int resx = ask(nx, ny); if(resx == -1){ goto AuJVIghY; } if(resx == 0){ x[qsz] = nx; y[qsz++] = ny; } } } AuJVIghY:; if(path[N-1][N-1] == 0){ wt_L("Yes"); wt_L('\n'); exit(0); } else{ wt_L("No"); wt_L('\n'); exit(0); } return 0; } // cLay version 20210405-1 // --- original code --- // //no-unlocked // //interactive // int x[1d6], y[1d6], qsz; // const int dx[] = {1, -1, 0, 0}; // const int dy[] = {0, 0, 1, -1}; // int path[510][1100]; // int N, M; // // bool within(int a, int b){ // return (0 <= a < N) && ( 0 <= b < N); // } // char res[100]; // int counts = 0; // int ask(int a, int b){ // if(path[a][b] != -1){ // return path[a][b]; // } // ++counts; // if(counts > 3000){ // return -1; // } // wt(a+1, b+1); // rd(res); // if(res[0] == 'B') path[a][b] = 0; // if(res[0] == 'W') path[a][b] = 1; // return path[a][b]; // } // // { // memset(path, 0xff, sizeof(path)); // rd(N, M); // x[0] = 0; y[0] = 0; qsz = 1; // bool ended = false; // path[0][0] = 0; // // rep(i, qsz){ // rep(j , 4){ // int nx = x[i] + dx[j]; // int ny = y[i] + dy[j]; // if(path[nx][ny] != -1) continue; // if(!within(nx, ny)) continue; // int resx = ask(nx, ny); // if(resx == -1){ // break_break; // } // if(resx == 0){ // x[qsz] = nx; // y[qsz++] = ny; // } // } // } // if(path[N-1][N-1] == 0){ // wt("Yes");exit(0); // }else{ // wt("No");exit(0); // } // }