結果

問題 No.1588 Connection
ユーザー umezoumezo
提出日時 2021-07-08 23:10:58
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,288 bytes
コンパイル時間 1,822 ms
使用メモリ 22,856 KB
平均クエリ数 547.62
最終ジャッジ日時 2023-02-15 01:05:41
合計ジャッジ時間 4,882 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 19 ms
21,744 KB
testcase_01 AC 18 ms
22,856 KB
testcase_02 AC 18 ms
21,928 KB
testcase_03 AC 18 ms
22,540 KB
testcase_04 AC 19 ms
21,992 KB
testcase_05 AC 18 ms
21,916 KB
testcase_06 AC 19 ms
22,456 KB
testcase_07 AC 18 ms
21,880 KB
testcase_08 AC 21 ms
21,868 KB
testcase_09 AC 22 ms
22,192 KB
testcase_10 AC 21 ms
22,252 KB
testcase_11 AC 18 ms
21,992 KB
testcase_12 AC 49 ms
21,968 KB
testcase_13 AC 55 ms
21,916 KB
testcase_14 AC 19 ms
21,880 KB
testcase_15 AC 20 ms
21,768 KB
testcase_16 AC 19 ms
21,892 KB
testcase_17 AC 21 ms
21,868 KB
testcase_18 AC 19 ms
22,264 KB
testcase_19 AC 19 ms
21,992 KB
testcase_20 AC 20 ms
21,756 KB
testcase_21 AC 94 ms
21,968 KB
testcase_22 AC 94 ms
21,880 KB
testcase_23 AC 49 ms
21,880 KB
testcase_24 AC 36 ms
21,868 KB
testcase_25 AC 57 ms
21,904 KB
testcase_26 AC 56 ms
21,928 KB
testcase_27 AC 35 ms
21,880 KB
testcase_28 AC 31 ms
22,596 KB
testcase_29 AC 93 ms
21,880 KB
testcase_30 AC 93 ms
21,768 KB
testcase_31 AC 19 ms
21,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0