結果
| 問題 |
No.1588 Connection
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-07-08 23:47:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,927 bytes |
| コンパイル時間 | 1,377 ms |
| コンパイル使用メモリ | 121,700 KB |
| 最終ジャッジ日時 | 2025-01-22 19:39:18 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | MLE * 1 |
| other | AC * 9 MLE * 22 |
ソースコード
#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;
}
milanis48663220