結果

問題 No.1588 Connection
ユーザー KudeKude
提出日時 2021-07-08 23:28:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,893 bytes
コンパイル時間 5,665 ms
コンパイル使用メモリ 264,120 KB
実行使用メモリ 24,228 KB
平均クエリ数 381.62
最終ジャッジ日時 2023-09-24 11:40:17
合計ジャッジ時間 7,637 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
23,472 KB
testcase_01 AC 27 ms
23,460 KB
testcase_02 AC 27 ms
23,580 KB
testcase_03 AC 26 ms
24,228 KB
testcase_04 AC 27 ms
23,436 KB
testcase_05 AC 26 ms
23,520 KB
testcase_06 AC 27 ms
23,340 KB
testcase_07 AC 26 ms
23,928 KB
testcase_08 AC 28 ms
23,976 KB
testcase_09 AC 28 ms
23,316 KB
testcase_10 AC 28 ms
23,436 KB
testcase_11 AC 28 ms
23,544 KB
testcase_12 AC 29 ms
23,976 KB
testcase_13 AC 30 ms
23,592 KB
testcase_14 AC 27 ms
24,216 KB
testcase_15 AC 29 ms
23,964 KB
testcase_16 AC 28 ms
24,204 KB
testcase_17 AC 27 ms
24,216 KB
testcase_18 AC 27 ms
23,940 KB
testcase_19 AC 27 ms
23,304 KB
testcase_20 AC 29 ms
23,532 KB
testcase_21 AC 77 ms
23,328 KB
testcase_22 AC 78 ms
23,472 KB
testcase_23 AC 48 ms
23,556 KB
testcase_24 AC 38 ms
23,916 KB
testcase_25 AC 70 ms
23,532 KB
testcase_26 AC 68 ms
23,340 KB
testcase_27 AC 44 ms
23,532 KB
testcase_28 AC 40 ms
23,280 KB
testcase_29 AC 100 ms
23,784 KB
testcase_30 AC 95 ms
24,216 KB
testcase_31 AC 26 ms
23,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int n, m;
int query(int i, int j) {
    cout << i + 1 << ' ' << j + 1 << endl;
    string ret;
    cin >> ret;
    if (ret == "-1") exit(0);
    return ret == "Black";
}

int state[500][500];
bool added[500][500];
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    rep(i, 500) rep(j, 500) state[i][j] = -1;
    state[0][0] = 1;
    cin >> n >> m;
    auto mycmp = [&](pair<int, P>& x, pair<int, P>& y) {
        return x.first > y.first;
    };
    priority_queue<pair<int, P>, vector<pair<int, P>>, decltype(mycmp)> q(mycmp);
    q.emplace(n - 1 + n - 1 - 1, P{0, 1});
    q.emplace(n - 1 + n - 1 - 1, P{1, 0});
    added[0][0] = added[0][1] = added[1][0] = true;
    rep(_, 3000) {
        if (q.empty()) break;
        auto [d, p] = q.top(); q.pop();
        if (d == 0) {
            cout << "Yes\n";
            return 0;
        }
        auto [i, j] = p;
        state[i][j] = query(i, j);
        if (state[i][j]) {
            rep(k, 4) {
                int ni = i + dx[k], nj = j + dy[k];
                if (!(0 <= ni && ni < n && 0 <= nj && nj < n)) continue;
                if (added[ni][nj]) continue;
                added[ni][nj] = true;
                q.emplace(n - 1 - ni + n - 1 - nj, P{ni, nj});
            }
        }
    }
    cout << "No\n";
}
0