結果

問題 No.1588 Connection
ユーザー trineutrontrineutron
提出日時 2021-07-08 22:55:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,426 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 209,052 KB
実行使用メモリ 24,396 KB
平均クエリ数 551.19
最終ジャッジ日時 2023-09-24 10:51:11
合計ジャッジ時間 5,692 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,388 KB
testcase_01 AC 25 ms
24,024 KB
testcase_02 AC 26 ms
23,628 KB
testcase_03 AC 26 ms
23,244 KB
testcase_04 AC 26 ms
23,844 KB
testcase_05 AC 24 ms
23,388 KB
testcase_06 AC 27 ms
24,348 KB
testcase_07 AC 26 ms
24,396 KB
testcase_08 AC 29 ms
23,424 KB
testcase_09 AC 29 ms
23,844 KB
testcase_10 AC 29 ms
23,640 KB
testcase_11 AC 29 ms
23,388 KB
testcase_12 AC 58 ms
24,024 KB
testcase_13 AC 66 ms
24,024 KB
testcase_14 AC 27 ms
23,652 KB
testcase_15 AC 28 ms
23,544 KB
testcase_16 AC 27 ms
23,424 KB
testcase_17 AC 25 ms
23,844 KB
testcase_18 AC 26 ms
23,424 KB
testcase_19 AC 26 ms
24,336 KB
testcase_20 AC 27 ms
23,652 KB
testcase_21 AC 106 ms
23,556 KB
testcase_22 AC 104 ms
24,300 KB
testcase_23 AC 59 ms
23,400 KB
testcase_24 AC 45 ms
24,060 KB
testcase_25 AC 69 ms
23,436 KB
testcase_26 AC 66 ms
24,312 KB
testcase_27 AC 43 ms
23,688 KB
testcase_28 AC 36 ms
24,336 KB
testcase_29 AC 104 ms
24,312 KB
testcase_30 AC 105 ms
24,060 KB
testcase_31 AC 26 ms
24,324 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