結果

問題 No.1588 Connection
ユーザー trineutrontrineutron
提出日時 2021-07-08 22:55:51
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,426 bytes
コンパイル時間 2,041 ms
使用メモリ 22,608 KB
平均クエリ数 551.19
最終ジャッジ日時 2023-02-15 00:10:24
合計ジャッジ時間 5,360 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 22 ms
21,756 KB
testcase_01 AC 21 ms
21,916 KB
testcase_02 AC 21 ms
21,916 KB
testcase_03 AC 21 ms
21,868 KB
testcase_04 AC 21 ms
21,928 KB
testcase_05 AC 20 ms
21,736 KB
testcase_06 AC 22 ms
21,968 KB
testcase_07 AC 21 ms
21,928 KB
testcase_08 AC 23 ms
21,880 KB
testcase_09 AC 23 ms
21,756 KB
testcase_10 AC 24 ms
21,892 KB
testcase_11 AC 25 ms
22,252 KB
testcase_12 AC 53 ms
22,420 KB
testcase_13 AC 58 ms
21,768 KB
testcase_14 AC 21 ms
21,880 KB
testcase_15 AC 22 ms
22,204 KB
testcase_16 AC 21 ms
21,916 KB
testcase_17 AC 24 ms
21,904 KB
testcase_18 AC 21 ms
21,880 KB
testcase_19 AC 22 ms
21,880 KB
testcase_20 AC 24 ms
22,600 KB
testcase_21 AC 102 ms
21,756 KB
testcase_22 AC 99 ms
22,608 KB
testcase_23 AC 53 ms
22,608 KB
testcase_24 AC 39 ms
22,216 KB
testcase_25 AC 62 ms
22,600 KB
testcase_26 AC 61 ms
21,916 KB
testcase_27 AC 38 ms
21,892 KB
testcase_28 AC 33 ms
22,432 KB
testcase_29 AC 98 ms
21,916 KB
testcase_30 AC 99 ms
22,552 KB
testcase_31 AC 21 ms
21,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using point = pair<int, int>;

enum
{
    unknown = 0,
    black = 1,
    white = 2,
};

vector dx{1, 0, -1, 0}, dy{0, 1, 0, -1};

int main()
{
    int n, m;
    cin >> n >> m;
    vector color(n, vector<int>(n, unknown));
    color.at(0).at(0) = black;
    queue<point> q;
    q.emplace(0, 0);
    while (not q.empty())
    {
        auto [x, y] = q.front();
        q.pop();
        for (int i = 0; i < 4; i++)
        {
            int x_next = x + dx.at(i), y_next = y + dy.at(i);
            if (x_next < 0 or n <= x_next or y_next < 0 or n <= y_next)
            {
                continue;
            }
            if (color.at(x_next).at(y_next) != unknown)
            {
                continue;
            }
            if (x_next == n - 1 and y_next == n - 1)
            {
                cout << "Yes" << endl;
                return 0;
            }
            cout << x_next + 1 << ' ' << y_next + 1 << endl;
            string res;
            cin >> res;
            if (res == "Black")
            {
                color.at(x_next).at(y_next) = black;
                q.emplace(x_next, y_next);
            }
            else if (res == "White")
            {
                color.at(x_next).at(y_next) = white;
            }
            else
            {
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}
0