結果

問題 No.1588 Connection
ユーザー Ricky_ponRicky_pon
提出日時 2021-07-08 23:37:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 3,013 bytes
コンパイル時間 2,379 ms
コンパイル使用メモリ 208,908 KB
実行使用メモリ 24,396 KB
平均クエリ数 44810.09
最終ジャッジ日時 2023-09-24 11:42:24
合計ジャッジ時間 10,189 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,324 KB
testcase_01 AC 23 ms
23,580 KB
testcase_02 AC 27 ms
23,364 KB
testcase_03 AC 27 ms
23,352 KB
testcase_04 AC 27 ms
24,348 KB
testcase_05 AC 26 ms
23,388 KB
testcase_06 AC 27 ms
23,616 KB
testcase_07 AC 29 ms
23,784 KB
testcase_08 AC 26 ms
23,652 KB
testcase_09 WA -
testcase_10 AC 26 ms
23,376 KB
testcase_11 AC 27 ms
23,328 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 74 ms
23,304 KB
testcase_15 AC 102 ms
23,940 KB
testcase_16 QLE -
testcase_17 QLE -
testcase_18 QLE -
testcase_19 QLE -
testcase_20 QLE -
testcase_21 QLE -
testcase_22 QLE -
testcase_23 QLE -
testcase_24 QLE -
testcase_25 QLE -
testcase_26 QLE -
testcase_27 QLE -
testcase_28 QLE -
testcase_29 QLE -
testcase_30 QLE -
testcase_31 AC 24 ms
23,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define For(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rFor(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) For(i, 0, (n))
#define rrep(i, n) rFor(i, (n), 0)
#define fi first
#define se second

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

template <typename T>
struct coord_comp {
    vector<T> v;
    bool sorted = false;

    coord_comp() {}

    int size() { return v.size(); }

    void add(T x) { v.push_back(x); }

    void build() {
        sort(v.begin(), v.end());

        v.erase(unique(v.begin(), v.end()), v.end());
        sorted = true;
    }

    int get_idx(T x) {
        assert(sorted);
        return lower_bound(v.begin(), v.end(), x) - v.begin();
    }

    T &operator[](int i) { return v[i]; }
};

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

typedef struct UnionFindTree {
    vector<int> par;

    UnionFindTree(int n) { par.resize(n, -1); }

    void clear() { fill(par.begin(), par.end(), -1); }

    bool is_root(int x) { return par[x] < 0; }

    int find(int x) {
        if (is_root(x)) return x;
        return par[x] = find(par[x]);
    }

    int size(int x) { return -par[find(x)]; }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }
} UF;

int n, m;
bool used[510][510];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int idx(int x, int y) { return x * n + y; }

string interact(int x, int y) {
    cout << x + 1 << " " << y + 1 << endl;
    string ret;
    cin >> ret;
    return ret;
}

int main() {
    scanf("%d%d", &n, &m);
    UF uf(n * n);
    queue<pii> que;
    que.emplace(0, 0);
    used[0][0] = true;
    while (!que.empty()) {
        auto [x, y] = que.front();
        que.pop();
        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (0 <= nx && nx < n && 0 <= ny && ny < n && !used[nx][ny]) {
                if (interact(nx, ny) == "Black")
                    uf.unite(idx(x, y), idx(nx, ny));
                que.emplace(nx, ny);
                used[nx][ny] = true;
            }
        }
    }
    cout << (uf.same(idx(0, 0), idx(n - 1, n - 1)) ? "Yes" : "No") << endl;
}
0