結果

問題 No.1588 Connection
ユーザー 👑Zack Ni👑Zack Ni
提出日時 2021-07-17 13:59:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 4,068 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 176,668 KB
実行使用メモリ 25,812 KB
平均クエリ数 563.00
最終ジャッジ日時 2023-09-24 12:11:38
合計ジャッジ時間 5,075 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
25,520 KB
testcase_01 AC 28 ms
25,024 KB
testcase_02 AC 27 ms
25,632 KB
testcase_03 AC 26 ms
25,100 KB
testcase_04 AC 28 ms
25,284 KB
testcase_05 AC 27 ms
25,580 KB
testcase_06 AC 28 ms
25,392 KB
testcase_07 AC 28 ms
25,236 KB
testcase_08 AC 29 ms
25,304 KB
testcase_09 AC 31 ms
25,400 KB
testcase_10 AC 31 ms
25,524 KB
testcase_11 AC 30 ms
25,448 KB
testcase_12 AC 60 ms
25,720 KB
testcase_13 AC 64 ms
25,416 KB
testcase_14 AC 26 ms
25,312 KB
testcase_15 AC 26 ms
25,632 KB
testcase_16 AC 25 ms
25,448 KB
testcase_17 AC 26 ms
25,364 KB
testcase_18 AC 27 ms
24,952 KB
testcase_19 AC 26 ms
25,632 KB
testcase_20 AC 28 ms
25,636 KB
testcase_21 AC 100 ms
25,416 KB
testcase_22 AC 95 ms
25,344 KB
testcase_23 AC 54 ms
25,568 KB
testcase_24 AC 40 ms
25,376 KB
testcase_25 AC 62 ms
25,348 KB
testcase_26 AC 61 ms
25,352 KB
testcase_27 AC 41 ms
25,196 KB
testcase_28 AC 38 ms
25,292 KB
testcase_29 AC 104 ms
25,684 KB
testcase_30 AC 100 ms
25,812 KB
testcase_31 AC 26 ms
25,264 KB
権限があれば一括ダウンロードができます

ソースコード

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 < 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);
//     }
// }
0