結果

問題 No.1588 Connection
ユーザー risujirohrisujiroh
提出日時 2021-07-08 23:03:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 1,018 bytes
コンパイル時間 2,962 ms
コンパイル使用メモリ 208,068 KB
実行使用メモリ 24,492 KB
平均クエリ数 3.00
最終ジャッジ日時 2023-09-24 11:29:27
合計ジャッジ時間 5,014 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,024 KB
testcase_01 WA -
testcase_02 AC 23 ms
24,024 KB
testcase_03 AC 23 ms
23,784 KB
testcase_04 AC 23 ms
23,616 KB
testcase_05 AC 24 ms
24,360 KB
testcase_06 AC 24 ms
23,388 KB
testcase_07 AC 24 ms
23,676 KB
testcase_08 AC 23 ms
24,300 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 23 ms
23,532 KB
testcase_15 AC 22 ms
24,288 KB
testcase_16 AC 22 ms
23,664 KB
testcase_17 AC 22 ms
24,372 KB
testcase_18 AC 22 ms
24,024 KB
testcase_19 AC 24 ms
23,508 KB
testcase_20 AC 27 ms
23,616 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 27 ms
23,856 KB
testcase_26 AC 26 ms
24,012 KB
testcase_27 AC 25 ms
23,412 KB
testcase_28 AC 25 ms
24,408 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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