結果

問題 No.1588 Connection
ユーザー 👑Zack Ni👑Zack Ni
提出日時 2021-07-17 13:42:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,025 bytes
コンパイル時間 1,909 ms
コンパイル使用メモリ 177,004 KB
実行使用メモリ 29,660 KB
平均クエリ数 11.06
最終ジャッジ日時 2023-09-24 12:10:54
合計ジャッジ時間 9,604 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
25,108 KB
testcase_01 WA -
testcase_02 AC 28 ms
25,540 KB
testcase_03 AC 28 ms
25,300 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 28 ms
25,344 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 28 ms
25,292 KB
testcase_17 AC 28 ms
25,564 KB
testcase_18 AC 28 ms
25,752 KB
testcase_19 AC 29 ms
25,224 KB
testcase_20 AC 30 ms
25,448 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
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 < M);
}
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;
  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(!within(nx, ny)){
        continue;
      }
      int resx = ask(nx, ny);
      if(resx == -1){
        wt_L("No");
        wt_L('\n');
        exit(0);
      }
      if(resx == 0){
        x[qsz++] = nx;
        y[qsz++] = ny;
        if(nx == N-1 && ny == M-1){
          wt_L("Yes");
          wt_L('\n');
          exit(0);
        }
      }
    }
  }
  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 < M);
// }
// 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;
//     rep(i, qsz){
//         rep(j , 4){
//             int nx = x[i] + dx[j];
//             int ny = y[i] + dy[j];
//             if(!within(nx, ny)) continue;
//             int resx = ask(nx, ny);
//             if(resx == -1){
//                 wt("No");
//                 exit(0);
//             }
//             if(resx == 0){
//                 x[qsz++] = nx;
//                 y[qsz++] = ny;
//                 if(nx == N-1 && ny == M-1){
//                     wt("Yes");
//                     exit(0);
//                 }
//             }
//         }
//     }
//     wt("No");exit(0);
// }
0