結果

問題 No.1588 Connection
ユーザー MZKiMZKi
提出日時 2021-07-09 00:02:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 1,475 ms
コンパイル使用メモリ 153,268 KB
実行使用メモリ 24,348 KB
平均クエリ数 563.00
最終ジャッジ日時 2023-09-24 11:51:08
合計ジャッジ時間 4,585 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,580 KB
testcase_01 AC 24 ms
24,288 KB
testcase_02 AC 24 ms
24,348 KB
testcase_03 AC 24 ms
23,340 KB
testcase_04 AC 24 ms
23,472 KB
testcase_05 AC 24 ms
23,436 KB
testcase_06 AC 25 ms
23,280 KB
testcase_07 AC 24 ms
23,448 KB
testcase_08 AC 26 ms
23,328 KB
testcase_09 AC 26 ms
23,604 KB
testcase_10 AC 26 ms
23,736 KB
testcase_11 AC 27 ms
23,904 KB
testcase_12 AC 57 ms
23,328 KB
testcase_13 AC 64 ms
24,264 KB
testcase_14 AC 25 ms
24,288 KB
testcase_15 AC 24 ms
23,328 KB
testcase_16 AC 23 ms
23,928 KB
testcase_17 AC 23 ms
24,120 KB
testcase_18 AC 24 ms
24,204 KB
testcase_19 AC 24 ms
24,204 KB
testcase_20 AC 26 ms
23,952 KB
testcase_21 AC 104 ms
23,964 KB
testcase_22 AC 102 ms
23,724 KB
testcase_23 AC 56 ms
23,568 KB
testcase_24 AC 43 ms
23,976 KB
testcase_25 AC 69 ms
23,736 KB
testcase_26 AC 65 ms
23,292 KB
testcase_27 AC 42 ms
24,324 KB
testcase_28 AC 35 ms
23,988 KB
testcase_29 AC 104 ms
23,472 KB
testcase_30 AC 107 ms
23,304 KB
testcase_31 AC 24 ms
23,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int ask(int a, int b){
    string ret;
    cout << a+1 << " " << b+1 << endl;
    cin >> ret;
    assert(ret != "-1");
    return (ret == "Black" ? 1 : 0);
}

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> dp(n, vector<int>(n, -1));
    bool ans = false;
    queue<pair<int, int>> que;
    que.push({0, 0});
    dp[0][0] = true;
    while(!que.empty()){
        pair<int, int> p = que.front();
        que.pop();
        int x = p.first, y = p.second;
        dp[x][y] = 1;
        rep(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || nx >= n || ny < 0 || ny >= n)continue;
            if(dp[nx][ny] != -1)continue;
            if(ask(nx, ny)){
                dp[nx][ny] = 1;
                que.push({nx, ny});
            }else{
                dp[nx][ny] = 0;
            }
        }
    }
    cout << (dp[n-1][n-1] == 1 ? "Yes" : "No") << endl;
}
0