結果

問題 No.1588 Connection
ユーザー SSRS
提出日時 2021-07-08 22:28:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 807 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 172,504 KB
実行使用メモリ 25,220 KB
平均クエリ数 563.00
最終ジャッジ日時 2024-07-17 11:35:47
合計ジャッジ時間 4,818 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
void dfs(vector<vector<int>> &S, int x, int y){
  int N = S.size();
  for (int i = 0; i < 4; i++){
    int x2 = x + dx[i];
    int y2 = y + dy[i];
    if (0 <= x2 && x2 < N && 0 <= y2 && y2 < N){
      if (S[x2][y2] == -1){
        cout << x2 + 1 << ' ' << y2 + 1 << endl;
        string s;
        cin >> s;
        if (s == "White"){
          S[x2][y2] = 0;
        }
        if (s == "Black"){
          S[x2][y2] = 1;
          dfs(S, x2, y2);
        }
      }
    }
  }
}
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> S(N, vector<int>(N, -1));
  S[0][0] = 1;
  dfs(S, 0, 0);
  if (S[N - 1][N - 1] == 1){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
0