結果

問題 No.1588 Connection
ユーザー norikamenorikame
提出日時 2021-07-09 10:58:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 2,121 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 174,600 KB
実行使用メモリ 24,312 KB
平均クエリ数 424.72
最終ジャッジ日時 2023-09-24 11:59:50
合計ジャッジ時間 4,676 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,132 KB
testcase_01 WA -
testcase_02 AC 26 ms
23,556 KB
testcase_03 AC 25 ms
23,724 KB
testcase_04 AC 25 ms
23,256 KB
testcase_05 AC 26 ms
23,472 KB
testcase_06 AC 24 ms
23,268 KB
testcase_07 AC 23 ms
23,988 KB
testcase_08 AC 26 ms
23,976 KB
testcase_09 AC 29 ms
23,292 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 62 ms
23,928 KB
testcase_14 AC 25 ms
23,352 KB
testcase_15 AC 25 ms
23,532 KB
testcase_16 AC 25 ms
23,556 KB
testcase_17 AC 26 ms
23,304 KB
testcase_18 AC 26 ms
23,460 KB
testcase_19 AC 26 ms
24,192 KB
testcase_20 AC 29 ms
23,268 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 60 ms
23,124 KB
testcase_24 AC 44 ms
23,412 KB
testcase_25 AC 69 ms
23,568 KB
testcase_26 AC 68 ms
23,472 KB
testcase_27 AC 44 ms
23,304 KB
testcase_28 AC 39 ms
23,616 KB
testcase_29 WA -
testcase_30 WA -
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, int qcnt) {
    if (qcnt >= 1500) {
        exit(0);
        return -1;
    }
    ++a; ++b;
    cout << a << ' ' << b << endl;
    string s;
    cin >> s;
    if (s == "Black") return 1;
    else if (s == "White") return 0;
    else if (s == "-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 = 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 >= 1499) break;
                int qres = query(ny, nx, qcnt);
                ++qcnt;
                if (qres == -1) { qcnt = 1500; exit(0); break; }
                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>=1499) break;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
0