結果

問題 No.1588 Connection
ユーザー milanis48663220milanis48663220
提出日時 2021-07-08 23:48:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,957 bytes
コンパイル時間 1,535 ms
コンパイル使用メモリ 123,156 KB
実行使用メモリ 24,324 KB
平均クエリ数 474.94
最終ジャッジ日時 2023-09-24 11:46:52
合計ジャッジ時間 4,637 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
23,436 KB
testcase_01 AC 22 ms
24,000 KB
testcase_02 AC 23 ms
23,532 KB
testcase_03 AC 23 ms
24,000 KB
testcase_04 AC 25 ms
23,772 KB
testcase_05 AC 24 ms
24,012 KB
testcase_06 AC 25 ms
23,352 KB
testcase_07 AC 23 ms
23,340 KB
testcase_08 AC 25 ms
24,324 KB
testcase_09 AC 26 ms
23,952 KB
testcase_10 AC 26 ms
23,508 KB
testcase_11 AC 26 ms
23,952 KB
testcase_12 AC 53 ms
23,736 KB
testcase_13 AC 55 ms
23,340 KB
testcase_14 AC 23 ms
23,292 KB
testcase_15 AC 23 ms
24,012 KB
testcase_16 AC 23 ms
23,952 KB
testcase_17 AC 23 ms
23,508 KB
testcase_18 AC 24 ms
23,952 KB
testcase_19 AC 25 ms
23,616 KB
testcase_20 AC 25 ms
24,192 KB
testcase_21 AC 89 ms
23,640 KB
testcase_22 AC 88 ms
23,772 KB
testcase_23 AC 52 ms
23,292 KB
testcase_24 AC 39 ms
23,940 KB
testcase_25 AC 65 ms
23,952 KB
testcase_26 AC 64 ms
23,280 KB
testcase_27 AC 44 ms
23,268 KB
testcase_28 AC 38 ms
24,264 KB
testcase_29 AC 65 ms
23,376 KB
testcase_30 AC 100 ms
23,352 KB
testcase_31 AC 25 ms
23,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

const string Black = "Black";
const string White = "White";

int dh[4] = {0, 0, -1, 1};
int dw[4] = {-1, 1, 0, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    vector<vector<bool>> asked(n, vector<bool>(n));
    vector<vector<bool>> ok(n, vector<bool>(n));
    auto ask = [&](int a, int b){
        if(a < 0 || a >= n || b < 0 || b >= n) return false;
        if(asked[a][b]) return ok[a][b] == true;
        cout << a+1 << ' ' << b+1 << endl;
        string t; cin >> t;
        ok[a][b] = t==Black;
        asked[a][b] = true;
        return ok[a][b] == true;
    };
    asked[0][0] = true;
    ok[0][0] = true;
    asked[n-1][n-1] = true;
    ok[n-1][n-1] = true;
    vector<vector<bool>> visited(n, vector<bool>(n));
    function<bool(int, int)> dfs = [&](int i, int j){
        visited[i][j] = true;
        if(i == n-1 && j == n-1) return true;
        for(int k = 0; k < 4; k++){
            int i_to = i+dh[k];
            int j_to = j+dw[k];
            if(ask(i_to, j_to)){
                if(!visited[i_to][j_to]) {
                    if(dfs(i_to, j_to)) return true;
                }
            }
        }
        return false;
    };
    if(dfs(0, 0)) cout << "Yes" << endl;
    else cout << "No" << endl;
}
0