結果

問題 No.1588 Connection
ユーザー sten_sansten_san
提出日時 2021-07-08 23:48:34
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 2,227 bytes
コンパイル時間 2,103 ms
使用メモリ 22,620 KB
平均クエリ数 551.06
最終ジャッジ日時 2023-02-15 01:21:32
合計ジャッジ時間 5,161 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 20 ms
22,528 KB
testcase_01 AC 21 ms
22,620 KB
testcase_02 AC 20 ms
21,892 KB
testcase_03 AC 21 ms
21,992 KB
testcase_04 AC 21 ms
21,880 KB
testcase_05 AC 22 ms
21,892 KB
testcase_06 AC 22 ms
21,928 KB
testcase_07 AC 20 ms
21,868 KB
testcase_08 AC 23 ms
22,004 KB
testcase_09 AC 24 ms
21,892 KB
testcase_10 AC 25 ms
21,992 KB
testcase_11 AC 25 ms
21,868 KB
testcase_12 AC 52 ms
22,564 KB
testcase_13 AC 57 ms
22,552 KB
testcase_14 AC 22 ms
22,564 KB
testcase_15 AC 22 ms
22,564 KB
testcase_16 AC 22 ms
21,768 KB
testcase_17 AC 22 ms
21,928 KB
testcase_18 AC 21 ms
22,264 KB
testcase_19 AC 22 ms
22,252 KB
testcase_20 AC 24 ms
21,928 KB
testcase_21 AC 97 ms
21,928 KB
testcase_22 AC 97 ms
22,216 KB
testcase_23 AC 51 ms
22,576 KB
testcase_24 AC 38 ms
22,004 KB
testcase_25 AC 61 ms
21,980 KB
testcase_26 AC 59 ms
22,216 KB
testcase_27 AC 37 ms
22,552 KB
testcase_28 AC 32 ms
21,916 KB
testcase_29 AC 96 ms
21,992 KB
testcase_30 AC 95 ms
21,928 KB
testcase_31 AC 20 ms
21,892 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