結果

問題 No.1588 Connection
ユーザー norikamenorikame
提出日時 2021-07-08 23:16:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 1,941 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 210,724 KB
実行使用メモリ 24,348 KB
平均クエリ数 551.16
最終ジャッジ日時 2023-09-24 11:35:29
合計ジャッジ時間 5,321 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,288 KB
testcase_01 WA -
testcase_02 AC 24 ms
23,940 KB
testcase_03 AC 24 ms
24,060 KB
testcase_04 AC 24 ms
24,300 KB
testcase_05 AC 25 ms
23,964 KB
testcase_06 AC 25 ms
23,652 KB
testcase_07 AC 25 ms
23,976 KB
testcase_08 AC 27 ms
23,532 KB
testcase_09 AC 27 ms
23,664 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 65 ms
23,352 KB
testcase_14 AC 26 ms
24,348 KB
testcase_15 AC 27 ms
24,288 KB
testcase_16 AC 26 ms
23,844 KB
testcase_17 AC 25 ms
23,328 KB
testcase_18 AC 26 ms
23,940 KB
testcase_19 AC 25 ms
23,784 KB
testcase_20 AC 26 ms
24,048 KB
testcase_21 WA -
testcase_22 AC 104 ms
23,424 KB
testcase_23 AC 57 ms
23,556 KB
testcase_24 AC 42 ms
23,592 KB
testcase_25 AC 65 ms
23,856 KB
testcase_26 AC 64 ms
23,364 KB
testcase_27 AC 42 ms
24,264 KB
testcase_28 AC 36 ms
24,060 KB
testcase_29 AC 97 ms
23,844 KB
testcase_30 AC 103 ms
23,628 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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);

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

int main() {
    int n, m;
    cin >> n >> m;
    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 = 2, qcnt = 0;
    bool ok = false;
    que.emplace(0, 0);
    dist[0][0] = 0;
    while (!que.empty()) {
        auto p = que.front(); que.pop();
        int y = p.first, x = p.second, d = dist[y][x];
        const vector<int> dy = { -1, 0, 1, 0 }, dx = { 0, 1, 0, -1 };
        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;
                break;
            }
            if (dist[ny][nx] <= d+1) continue;
            if (b[ny][nx] == -1) {
                if (mcnt >= m) break;
                if (qcnt >= 2999) break;
                int qres = query(ny, nx);
                ++qcnt;
                if (qres == 1) ++mcnt;
                b[ny][nx] = qres;
            }
            if (b[ny][nx] == 0) continue;
            if (b[ny][nx] == 1) {
                que.emplace(ny, nx);
                dist[ny][nx] = d + 1;
            }
        }
        if (ok || mcnt>=m || qcnt>=3000) break;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
0