結果

問題 No.1588 Connection
ユーザー merom686merom686
提出日時 2021-07-09 00:10:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 1,438 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 204,520 KB
実行使用メモリ 24,336 KB
平均クエリ数 425.06
最終ジャッジ日時 2023-09-24 11:52:08
合計ジャッジ時間 5,110 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,952 KB
testcase_01 AC 25 ms
23,484 KB
testcase_02 AC 26 ms
23,304 KB
testcase_03 AC 25 ms
23,616 KB
testcase_04 AC 26 ms
23,604 KB
testcase_05 AC 25 ms
23,460 KB
testcase_06 AC 26 ms
23,568 KB
testcase_07 AC 25 ms
23,544 KB
testcase_08 AC 24 ms
23,940 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 27 ms
23,964 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 25 ms
23,316 KB
testcase_15 AC 26 ms
23,952 KB
testcase_16 AC 25 ms
23,472 KB
testcase_17 AC 25 ms
23,448 KB
testcase_18 AC 24 ms
23,328 KB
testcase_19 AC 25 ms
23,964 KB
testcase_20 AC 28 ms
23,304 KB
testcase_21 AC 105 ms
23,988 KB
testcase_22 AC 107 ms
23,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 69 ms
23,964 KB
testcase_26 AC 67 ms
24,156 KB
testcase_27 AC 43 ms
23,952 KB
testcase_28 AC 28 ms
23,604 KB
testcase_29 AC 102 ms
23,748 KB
testcase_30 AC 106 ms
23,460 KB
testcase_31 AC 26 ms
24,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int a[502][502];

int main() {
    int n, m;
    cin >> n >> m;

    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n + 1; j++) {
            a[i][j] = -1;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            a[i][j] = 0;
        }
    }

    a[1][1] = 1;
    a[n][n] = 1;
    m -= 2;

    queue<pair<int, int>> q;
    q.push({ 1, 1 });

    int l = 0;

    while (!q.empty() && m > 0) {
        auto p = q.back(); q.pop();
        pair<int, int> d[4] = { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } };
        for (int k = 0; k < 4; k++) {
            auto t = p;
            t.first += d[k].first;
            t.second += d[k].second;
            int &x = a[t.first][t.second];
            if (x != 0) continue;
            if (l == 3000) break;
            cout << t.first << ' ' << t.second << endl;
            l++;
            string s;
            cin >> s;
            if (s[0] == '-') {
                exit(0);
            }
            x = s[0] == 'B' ? 1 : 2;
            if (x == 1) {
                if ((t.first == n - 1 && t.second == n) || (t.first == n && t.second == n - 1)) {
                    cout << "Yes" << endl;
                    exit(0);
                }
                q.push(t);
                m--;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}
0