結果

問題 No.1588 Connection
ユーザー milanis48663220milanis48663220
提出日時 2021-07-08 23:47:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,927 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 124,988 KB
実行使用メモリ 823,456 KB
平均クエリ数 0.09
最終ジャッジ日時 2023-09-24 11:46:01
合計ジャッジ時間 3,469 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
23,340 KB
testcase_01 MLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

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){
        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