結果

問題 No.1588 Connection
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-04-19 00:37:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,356 bytes
コンパイル時間 1,412 ms
コンパイル使用メモリ 121,180 KB
実行使用メモリ 25,464 KB
平均クエリ数 551.78
最終ジャッジ日時 2024-04-22 01:47:22
合計ジャッジ時間 4,919 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
25,220 KB
testcase_01 AC 24 ms
24,580 KB
testcase_02 AC 24 ms
24,580 KB
testcase_03 AC 24 ms
24,964 KB
testcase_04 AC 24 ms
24,824 KB
testcase_05 AC 24 ms
24,580 KB
testcase_06 AC 26 ms
24,836 KB
testcase_07 AC 24 ms
24,836 KB
testcase_08 AC 27 ms
24,964 KB
testcase_09 AC 27 ms
24,568 KB
testcase_10 AC 28 ms
25,204 KB
testcase_11 AC 28 ms
25,220 KB
testcase_12 AC 57 ms
24,836 KB
testcase_13 AC 63 ms
25,220 KB
testcase_14 AC 25 ms
25,220 KB
testcase_15 AC 25 ms
24,580 KB
testcase_16 AC 25 ms
24,580 KB
testcase_17 AC 26 ms
24,836 KB
testcase_18 AC 25 ms
24,836 KB
testcase_19 AC 25 ms
25,220 KB
testcase_20 AC 28 ms
24,836 KB
testcase_21 AC 104 ms
24,964 KB
testcase_22 AC 105 ms
24,964 KB
testcase_23 AC 57 ms
24,964 KB
testcase_24 AC 41 ms
24,836 KB
testcase_25 AC 70 ms
25,220 KB
testcase_26 AC 67 ms
24,580 KB
testcase_27 AC 42 ms
24,836 KB
testcase_28 AC 37 ms
25,464 KB
testcase_29 AC 100 ms
25,220 KB
testcase_30 AC 101 ms
24,580 KB
testcase_31 AC 25 ms
25,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

int main(){

    int H, W, h, w, nh, nw, x;
    cin >> H >> x;
    string res;
    W = H;
    
    queue<pair<int, int>> que;
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    vector<vector<int>> dist(H, vector<int>(W, -1));
    vector<vector<int>> field(H, vector<int>(W));

    dist[0][0] = 0;
    que.push({0, 0});

    while(!que.empty()){
        tie(h, w) = que.front();
        if (h == H-1 && w == W-1){
            cout << "Yes" << endl;
            return 0;
        }
        que.pop();
        for (int dir=0; dir < 4; dir++){
            nh = h + dx[dir];
            nw = w + dy[dir];
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (dist[nh][nw] != -1) continue;
            if (field[nh][nw] == -1) continue;
            cout << nh+1 << " " << nw+1 << endl;
            cin >> res;
            if (res == "-1") exit(0);
            else if (res == "Black"){
                dist[nh][nw] = dist[h][w] + 1;
                que.push({nh, nw});
            }
            else field[nh][nw] = -1;
        }
    }

    cout << "No" << endl;

    return 0;
}
0