結果

問題 No.1588 Connection
ユーザー norikamenorikame
提出日時 2021-07-09 11:34:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,160 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 210,248 KB
実行使用メモリ 24,336 KB
平均クエリ数 551.25
最終ジャッジ日時 2023-09-24 12:00:02
合計ジャッジ時間 5,573 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,580 KB
testcase_01 AC 26 ms
24,276 KB
testcase_02 AC 27 ms
23,568 KB
testcase_03 AC 28 ms
23,904 KB
testcase_04 AC 27 ms
23,580 KB
testcase_05 AC 27 ms
23,868 KB
testcase_06 AC 28 ms
23,556 KB
testcase_07 AC 26 ms
23,568 KB
testcase_08 AC 29 ms
23,964 KB
testcase_09 AC 29 ms
23,904 KB
testcase_10 AC 30 ms
23,400 KB
testcase_11 AC 30 ms
23,328 KB
testcase_12 AC 60 ms
24,108 KB
testcase_13 AC 67 ms
23,304 KB
testcase_14 AC 27 ms
23,412 KB
testcase_15 AC 29 ms
24,036 KB
testcase_16 AC 27 ms
23,472 KB
testcase_17 AC 27 ms
23,748 KB
testcase_18 AC 28 ms
23,400 KB
testcase_19 AC 28 ms
23,604 KB
testcase_20 AC 30 ms
23,340 KB
testcase_21 AC 110 ms
23,700 KB
testcase_22 AC 108 ms
23,556 KB
testcase_23 AC 59 ms
23,292 KB
testcase_24 AC 44 ms
24,336 KB
testcase_25 AC 72 ms
23,736 KB
testcase_26 AC 69 ms
23,628 KB
testcase_27 AC 44 ms
23,988 KB
testcase_28 AC 40 ms
24,072 KB
testcase_29 AC 107 ms
24,300 KB
testcase_30 AC 107 ms
23,328 KB
testcase_31 AC 27 ms
23,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const int INF = (int)(1e9);
const vector<int> dy = { -1, 0, 1, 0 }, dx = { 0, 1, 0, -1 };

int query(int a, int b, int& qcnt) {
    if (qcnt >= 3000) return -1;
    ++a; ++b; ++qcnt;
    cout << a << " " << b << endl;
    string s;
    cin >> s;
    if (s == (string)"Black") return 1;
    else if (s == (string)"White") return 0;
    else if (s == (string)"-1") return -1;
    else return -1;
}

int main() {
    int n, m;
    cin >> n >> m;
    cin.ignore();
    vector<vector<int>> b(n, vector<int>(n, -1));
    b[0][0] = b[n-1][n-1] = 1;
    queue<pair<int, int>> que;
    vector<vector<int>> dist(n, vector<int>(n, INF));
    int mcnt = 1, qcnt = 0;
    bool ok = false, br = false;
    que.emplace(0, 0);
    dist[0][0] = 0;
    while (!que.empty() && !br) {
        auto p = que.front(); que.pop();
        int y = p.first, x = p.second, d = dist[y][x];
        rep(i1, 4) {
            int ny = y + dy[i1], nx = x + dx[i1];
            if (ny<0 || ny>=n || nx<0 || nx>=n) continue;
            if (ny==n-1 && nx==n-1) {
                ok = true; br = true;
                break;
            }
            if (dist[ny][nx] <= d+1) continue;
            if (b[ny][nx] == -1) {
                if (mcnt >= m) {
                    br = true;
                    break;
                }
                int qres = query(ny, nx, qcnt);
                if (qres == -1) {
                    br = true;
                    break;
                }
                b[ny][nx] = qres;
            }
            if (b[ny][nx] == 0) continue;
            if (b[ny][nx] == 1) {
                que.emplace(ny, nx);
                dist[ny][nx] = d + 1;
                ++mcnt;
            }
        }
        if (ok || br) break;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
0