結果

問題 No.1588 Connection
ユーザー umezoumezo
提出日時 2021-07-08 23:10:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,288 bytes
コンパイル時間 2,059 ms
コンパイル使用メモリ 205,080 KB
実行使用メモリ 24,420 KB
平均クエリ数 547.62
最終ジャッジ日時 2023-09-24 11:33:21
合計ジャッジ時間 5,386 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,324 KB
testcase_01 AC 26 ms
23,676 KB
testcase_02 AC 26 ms
23,844 KB
testcase_03 AC 26 ms
23,424 KB
testcase_04 AC 26 ms
24,240 KB
testcase_05 AC 26 ms
23,412 KB
testcase_06 AC 27 ms
24,420 KB
testcase_07 AC 25 ms
23,820 KB
testcase_08 AC 28 ms
24,036 KB
testcase_09 AC 29 ms
23,640 KB
testcase_10 AC 29 ms
24,240 KB
testcase_11 AC 26 ms
23,640 KB
testcase_12 AC 60 ms
24,252 KB
testcase_13 AC 66 ms
24,024 KB
testcase_14 AC 26 ms
24,324 KB
testcase_15 AC 27 ms
23,640 KB
testcase_16 AC 26 ms
23,364 KB
testcase_17 AC 26 ms
24,036 KB
testcase_18 AC 26 ms
23,820 KB
testcase_19 AC 27 ms
23,628 KB
testcase_20 AC 28 ms
23,364 KB
testcase_21 AC 107 ms
23,640 KB
testcase_22 AC 103 ms
24,420 KB
testcase_23 AC 59 ms
23,856 KB
testcase_24 AC 43 ms
24,036 KB
testcase_25 AC 66 ms
23,400 KB
testcase_26 AC 66 ms
24,048 KB
testcase_27 AC 44 ms
23,424 KB
testcase_28 AC 39 ms
24,036 KB
testcase_29 AC 103 ms
24,420 KB
testcase_30 AC 103 ms
24,312 KB
testcase_31 AC 27 ms
23,556 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