結果
問題 | No.1588 Connection |
ユーザー |
|
提出日時 | 2021-07-08 22:51:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 561 bytes |
コンパイル時間 | 670 ms |
コンパイル使用メモリ | 65,172 KB |
実行使用メモリ | 25,220 KB |
平均クエリ数 | 562.59 |
最終ジャッジ日時 | 2024-07-17 11:41:26 |
合計ジャッジ時間 | 4,097 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 31 |
コンパイルメッセージ
main.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 27 | main() | ^~~~
ソースコード
#include<iostream> #include<cstdlib> using namespace std; int N,M; int T[501][501]; bool ask(int x,int y) { if(T[x][y])return T[x][y]==1; cout<<x<<" "<<y<<endl; string r;cin>>r; if(r=="-1")exit(1); T[x][y]=r=="Black"?1:-1; return T[x][y]==1; } int d[5]={0,1,0,-1}; bool vis[501][501]; void dfs(int x,int y) { vis[x][y]=true; for(int r=0;r<4;r++) { int tx=x+d[r],ty=y+d[r+1]; if(tx<1||ty<1||tx>N||ty>N||vis[tx][ty])continue; if(ask(tx,ty))dfs(tx,ty); } } main() { cin>>N>>M; T[1][1]=T[N][N]=1; dfs(1,1); cout<<(vis[N][N]?"Yes":"No")<<endl; }