結果

問題 No.1588 Connection
ユーザー risujirohrisujiroh
提出日時 2021-07-08 23:03:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,018 bytes
コンパイル時間 2,240 ms
コンパイル使用メモリ 209,108 KB
実行使用メモリ 24,336 KB
平均クエリ数 344.22
最終ジャッジ日時 2023-09-24 11:29:54
合計ジャッジ時間 5,358 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,424 KB
testcase_01 AC 27 ms
23,352 KB
testcase_02 AC 27 ms
24,324 KB
testcase_03 AC 27 ms
24,024 KB
testcase_04 AC 26 ms
24,012 KB
testcase_05 AC 27 ms
24,276 KB
testcase_06 AC 27 ms
23,520 KB
testcase_07 AC 26 ms
23,640 KB
testcase_08 AC 30 ms
23,388 KB
testcase_09 AC 27 ms
24,036 KB
testcase_10 AC 27 ms
23,640 KB
testcase_11 AC 27 ms
23,796 KB
testcase_12 AC 29 ms
23,796 KB
testcase_13 AC 30 ms
23,628 KB
testcase_14 AC 26 ms
23,784 KB
testcase_15 AC 28 ms
24,336 KB
testcase_16 AC 27 ms
24,288 KB
testcase_17 AC 26 ms
23,844 KB
testcase_18 AC 27 ms
23,628 KB
testcase_19 AC 27 ms
23,364 KB
testcase_20 AC 29 ms
23,376 KB
testcase_21 AC 76 ms
23,196 KB
testcase_22 AC 77 ms
23,664 KB
testcase_23 AC 46 ms
23,340 KB
testcase_24 AC 37 ms
23,388 KB
testcase_25 AC 68 ms
24,024 KB
testcase_26 AC 68 ms
24,336 KB
testcase_27 AC 44 ms
24,060 KB
testcase_28 AC 38 ms
24,048 KB
testcase_29 AC 87 ms
23,664 KB
testcase_30 AC 70 ms
23,376 KB
testcase_31 AC 26 ms
23,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector a(n, vector<int>(n, -1));
  a[0][0] = 1;
  a[n - 1][n - 1] = 1;
  auto query = [&](int i, int j) -> bool {
    if (a[i][j] != -1) return a[i][j];
    cout << i + 1 << ' ' << j + 1 << endl;
    string s;
    cin >> s;
    return (a[i][j] = s[0] == 'B');
  };
  constexpr array di{1, 0, -1, 0};
  constexpr array dj{0, 1, 0, -1};
  vector visited(n, vector<bool>(n));
  auto dfs = [&](auto self, int i, int j) -> void {
    if (i == n - 1 && j == n - 1) {
      cout << "Yes" << endl;
      exit(0);
    }
    for (int d : {0, 1, 2, 3}) {
      int ni = i + di[d];
      int nj = j + dj[d];
      if (min(ni, nj) < 0 || max(ni, nj) >= n || !query(ni, nj)) continue;
      if (visited[ni][nj]) continue;
      visited[ni][nj] = true;
      self(self, ni, nj);
    }
  };
  visited[0][0] = true;
  dfs(dfs, 0, 0);
  cout << "No" << endl;
}
0