結果

問題 No.1588 Connection
ユーザー kuc_jackson
提出日時 2021-07-09 10:03:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 199,440 KB
最終ジャッジ日時 2025-01-22 20:02:13
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

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