結果
| 問題 |
No.1588 Connection
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-17 13:42:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,025 bytes |
| コンパイル時間 | 2,168 ms |
| コンパイル使用メモリ | 178,064 KB |
| 実行使用メモリ | 30,380 KB |
| 平均クエリ数 | 11.06 |
| 最終ジャッジ日時 | 2024-07-17 13:04:32 |
| 合計ジャッジ時間 | 9,400 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 9 WA * 1 RE * 21 |
ソースコード
#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);
// }