結果

問題 No.1588 Connection
ユーザー sten_sansten_san
提出日時 2021-07-08 23:48:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 2,227 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 211,996 KB
実行使用メモリ 24,264 KB
平均クエリ数 551.06
最終ジャッジ日時 2023-09-24 11:46:24
合計ジャッジ時間 5,672 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,964 KB
testcase_01 AC 26 ms
23,568 KB
testcase_02 AC 26 ms
23,976 KB
testcase_03 AC 26 ms
23,316 KB
testcase_04 AC 26 ms
23,364 KB
testcase_05 AC 26 ms
23,460 KB
testcase_06 AC 28 ms
23,520 KB
testcase_07 AC 25 ms
23,556 KB
testcase_08 AC 28 ms
23,568 KB
testcase_09 AC 29 ms
23,616 KB
testcase_10 AC 30 ms
23,976 KB
testcase_11 AC 30 ms
24,264 KB
testcase_12 AC 59 ms
23,604 KB
testcase_13 AC 63 ms
23,568 KB
testcase_14 AC 27 ms
23,364 KB
testcase_15 AC 28 ms
24,156 KB
testcase_16 AC 26 ms
23,580 KB
testcase_17 AC 26 ms
23,604 KB
testcase_18 AC 26 ms
23,316 KB
testcase_19 AC 26 ms
23,976 KB
testcase_20 AC 29 ms
23,616 KB
testcase_21 AC 102 ms
23,952 KB
testcase_22 AC 106 ms
23,352 KB
testcase_23 AC 57 ms
23,928 KB
testcase_24 AC 45 ms
23,352 KB
testcase_25 AC 69 ms
23,604 KB
testcase_26 AC 67 ms
23,364 KB
testcase_27 AC 44 ms
23,592 KB
testcase_28 AC 38 ms
23,364 KB
testcase_29 AC 103 ms
23,604 KB
testcase_30 AC 101 ms
23,988 KB
testcase_31 AC 27 ms
23,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

optional<bool> memo[500][500];

bool query(int y, int x) {
    if (memo[y][x]) {
        return *memo[y][x];
    }

    cout << y + 1 << ' ' << x + 1 << endl;

    string t; cin >> t;

    if (t == "Black") {
        return *(memo[y][x] = true);
    }

    if (t == "White") {
        return *(memo[y][x] = false);
    }

    exit(1);
}

int main() {
    constexpr int step[4][2] = {
        { 1, 0 }, { 0, 1 }, { -1, 0 } , { 0, -1 },
    };

    int n, m; cin >> n >> m;

    memo[0][0] = true;
    memo[n - 1][n - 1] = true;

    if (m < 2 * n - 1) {
        cout << "No" << endl;
        return 0;
    }
    --m;

    queue<tuple<int, int>> que;
    auto vis = vec<bool>(false, n, n);

    que.push({ 0, 0 });
    vis[0][0] = true;
    while (!empty(que) && !vis[n - 1][n - 1] && m != 0) {
        auto [cy, cx] = que.front(); que.pop();

        for (auto [dy, dx] : step) {
            if (vis[n - 1][n - 1] || m == 0) {
                break;
            }

            int ny = cy + dy;
            int nx = cx + dx;

            if (min(ny, nx) < 0 || n <= max(ny, nx)) {
                continue;
            }

            if (vis[ny][nx]) {
                continue;
            }

            if (query(ny, nx)) {
                vis[ny][nx] = true;
                que.push({ ny, nx });
                --m;
            }
        }
    }

    cout << (vis[n - 1][n - 1] ? "Yes" : "No") << endl;
}

0