結果

問題 No.1588 Connection
ユーザー kuc_jacksonkuc_jackson
提出日時 2021-07-09 10:03:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 203,436 KB
実行使用メモリ 24,324 KB
平均クエリ数 344.94
最終ジャッジ日時 2023-09-24 11:58:29
合計ジャッジ時間 5,225 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,748 KB
testcase_01 AC 26 ms
23,232 KB
testcase_02 AC 27 ms
23,496 KB
testcase_03 AC 26 ms
24,180 KB
testcase_04 AC 27 ms
23,868 KB
testcase_05 AC 27 ms
23,208 KB
testcase_06 AC 29 ms
24,000 KB
testcase_07 AC 27 ms
23,496 KB
testcase_08 AC 29 ms
23,220 KB
testcase_09 AC 27 ms
24,084 KB
testcase_10 AC 27 ms
23,292 KB
testcase_11 AC 26 ms
23,748 KB
testcase_12 AC 30 ms
23,508 KB
testcase_13 AC 29 ms
23,604 KB
testcase_14 AC 26 ms
23,748 KB
testcase_15 AC 28 ms
23,352 KB
testcase_16 AC 27 ms
23,376 KB
testcase_17 AC 27 ms
23,292 KB
testcase_18 AC 27 ms
23,244 KB
testcase_19 AC 27 ms
23,916 KB
testcase_20 AC 29 ms
24,324 KB
testcase_21 AC 78 ms
23,352 KB
testcase_22 AC 78 ms
23,316 KB
testcase_23 AC 46 ms
23,472 KB
testcase_24 AC 37 ms
24,168 KB
testcase_25 AC 68 ms
23,580 KB
testcase_26 AC 69 ms
23,976 KB
testcase_27 AC 44 ms
23,616 KB
testcase_28 AC 38 ms
24,120 KB
testcase_29 AC 90 ms
23,856 KB
testcase_30 AC 68 ms
23,472 KB
testcase_31 AC 26 ms
24,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

int N, M;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vector<vector<int>> grid;

bool dfs(int h, int w){
    if(h == N - 1 && w == N - 1)return true;
    for(int i = 0; i < 4; i++){
        int nh = h + dx[i], nw = w + dy[i];
        if(nh < 0 || nh > N - 1 || nw < 0 || nw > N - 1)continue;
        if(grid[nh][nw] != -1)continue;
        cout << nh + 1 << " " << nw + 1 << endl;
        string s;
        cin >> s;
        grid[nh][nw] = 1;
        if(s == "Black"){
            if(dfs(nh, nw))return true;
        }
    }
    return false;
}

int main(){
    cin >> N >> M;
    grid = vector<vector<int>>(N, vector<int>(N, -1));
    cout << (dfs(0, 0) ? "Yes": "No") << endl;
}
0