結果
| 問題 |
No.1588 Connection
|
| コンテスト | |
| ユーザー |
ikashoppin
|
| 提出日時 | 2021-07-09 00:08:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 2,000 ms |
| コード長 | 1,732 bytes |
| コンパイル時間 | 1,772 ms |
| コンパイル使用メモリ | 201,544 KB |
| 最終ジャッジ日時 | 2025-01-22 19:50:16 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 31 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>
ostream &operator<<(ostream &os, const vector<T> &x){
os << "{";
for(size_t i = 0; i < x.size(); i++){
if(i < x.size()-1) os << x[i] << ", ";
else os << x[i];
}
os << "}";
return os;
}
const int di[] = {0, 0, -1, 1};
const int dj[] = {-1, 1, 0, 0};
int main(void){
int n, m;
cin >> n >> m;
vector<vector<int>> g(n, vector<int>(n, -1));
g[0][0] = g[n-1][n-1] = 0;
function<int(int, int)> query = [&](int x, int y){
if(g[x][y] != -1) return g[x][y];
string res;
cout << (x+1) << " " << (y+1) << endl;
cin >> res;
if(res == "-1") return -1;
else if(res == "Black") return g[x][y] = 0;
else if(res == "White") return g[x][y] = 1;
return -1;
};
vector<int> seen(n*n);
function<bool(int)> dfs = [&](int x){
if(x == n*n-1) return true;
if(seen[x]) return false;
seen[x] = true;
int i = x/n;
int j = x%n;
int c = query(i, j);
if(c == 1 || c == -1) return false;
rep(k, 4){
int ni = i+di[k];
int nj = j+dj[k];
if(ni < 0 || nj < 0 || ni >= n || nj >= n) continue;
int nx = ni*n+nj;
if(dfs(nx)){
return true;
}
}
return false;
};
bool f = dfs(0);
if(f) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
ikashoppin