結果

問題 No.1588 Connection
ユーザー rtyurtyu
提出日時 2021-07-12 10:57:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 78,348 KB
実行使用メモリ 24,336 KB
平均クエリ数 563.00
最終ジャッジ日時 2023-09-24 12:05:13
合計ジャッジ時間 4,162 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,904 KB
testcase_01 AC 26 ms
23,964 KB
testcase_02 AC 26 ms
23,904 KB
testcase_03 AC 26 ms
23,328 KB
testcase_04 AC 26 ms
24,336 KB
testcase_05 AC 25 ms
23,304 KB
testcase_06 AC 28 ms
23,544 KB
testcase_07 AC 26 ms
23,556 KB
testcase_08 AC 29 ms
23,844 KB
testcase_09 AC 29 ms
23,436 KB
testcase_10 AC 30 ms
23,136 KB
testcase_11 AC 29 ms
23,292 KB
testcase_12 AC 57 ms
23,616 KB
testcase_13 AC 62 ms
24,012 KB
testcase_14 AC 27 ms
23,460 KB
testcase_15 AC 28 ms
23,436 KB
testcase_16 AC 26 ms
23,448 KB
testcase_17 AC 26 ms
23,628 KB
testcase_18 AC 27 ms
23,304 KB
testcase_19 AC 27 ms
23,304 KB
testcase_20 AC 28 ms
23,436 KB
testcase_21 AC 108 ms
23,892 KB
testcase_22 AC 107 ms
23,748 KB
testcase_23 AC 58 ms
23,568 KB
testcase_24 AC 45 ms
23,412 KB
testcase_25 AC 67 ms
23,856 KB
testcase_26 AC 65 ms
23,616 KB
testcase_27 AC 43 ms
23,412 KB
testcase_28 AC 38 ms
23,724 KB
testcase_29 AC 106 ms
23,412 KB
testcase_30 AC 108 ms
23,964 KB
testcase_31 AC 26 ms
23,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

int r[509][509], dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
queue<pair<int, int> > q;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin >> n >> m;
    q.push(make_pair(1, 1));
    r[1][1] = 1;
    while (!q.empty()) {
        int y = q.front().first, x = q.front().second; q.pop();
        for (int i = 0; i < 4; i++) {
            int tx = x + dx[i], ty = y + dy[i];
            if (tx < 1 || tx > n || ty < 1 || ty > n || r[ty][tx]) continue;
            cout << ty << " " << tx << endl;
            string s; cin >> s;
            if (s[0] == 'B') {
                r[ty][tx] = 1;
                q.push(make_pair(ty, tx));
            }
            else
                r[ty][tx] = -1;
        }
    }
    if (r[n][n] == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
0