結果
問題 | No.1588 Connection |
ユーザー |
![]() |
提出日時 | 2021-07-08 23:10:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 117 ms / 2,000 ms |
コード長 | 1,288 bytes |
コンパイル時間 | 2,224 ms |
コンパイル使用メモリ | 199,000 KB |
最終ジャッジ日時 | 2025-01-22 19:14:22 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 31 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; int A[510][510]; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,m; cin>>n>>m; if(m<2*n-1){ cout<<"No"<<endl; return 0; } if(m>=n*n-1){ cout<<"Yes"<<endl; return 0; } A[1][1]=1,A[n][n]=1; queue<pair<int,int>> q; q.push({1,1}); int cnt=0; int res=m-2; int ma=0; while(!q.empty()){ auto t=q.front(); q.pop(); int y=t.first,x=t.second; rep(i,4){ int ny=y+dy[i],nx=x+dx[i]; if(ny<1 || ny>n || nx<1 || nx>n) continue; if(A[ny][nx]>0) continue; cout<<ny<<" "<<nx<<endl; cnt++; string t; cin>>t; if(t=="Black"){ A[ny][nx]=1; q.push({ny,nx}); res--; ma=max(ma,ny+nx); if(2*n-ma-1>m){ cout<<"No"<<endl; return 0; } if((ny==n-1 && nx==n) || (ny==n && nx==n-1)){ cout<<"Yes"<<endl; return 0; } } else if(t=="White"){ A[ny][nx]=2; } else if(t=="-1") return 0; } if(cnt>=3000) break; } cout<<"No"<<endl; return 0; }