結果
問題 | No.1588 Connection |
ユーザー |
![]() |
提出日時 | 2021-07-08 23:48:52 |
言語 | C++17 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 99 ms / 2,000 ms |
コード長 | 1,957 bytes |
コンパイル時間 | 1,069 ms |
使用メモリ | 22,856 KB |
平均クエリ数 | 474.94 |
最終ジャッジ日時 | 2023-02-15 01:22:08 |
合計ジャッジ時間 | 4,145 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
21,980 KB |
testcase_01 | AC | 21 ms
21,768 KB |
testcase_02 | AC | 20 ms
22,192 KB |
testcase_03 | AC | 20 ms
22,588 KB |
testcase_04 | AC | 21 ms
21,768 KB |
testcase_05 | AC | 20 ms
22,216 KB |
testcase_06 | AC | 21 ms
22,540 KB |
testcase_07 | AC | 20 ms
21,880 KB |
testcase_08 | AC | 23 ms
22,564 KB |
testcase_09 | AC | 23 ms
22,444 KB |
testcase_10 | AC | 23 ms
21,928 KB |
testcase_11 | AC | 23 ms
22,192 KB |
testcase_12 | AC | 51 ms
21,868 KB |
testcase_13 | AC | 55 ms
21,892 KB |
testcase_14 | AC | 21 ms
22,432 KB |
testcase_15 | AC | 22 ms
21,768 KB |
testcase_16 | AC | 21 ms
22,704 KB |
testcase_17 | AC | 21 ms
21,880 KB |
testcase_18 | AC | 22 ms
22,432 KB |
testcase_19 | AC | 21 ms
21,880 KB |
testcase_20 | AC | 22 ms
21,832 KB |
testcase_21 | AC | 84 ms
21,928 KB |
testcase_22 | AC | 85 ms
22,564 KB |
testcase_23 | AC | 46 ms
22,852 KB |
testcase_24 | AC | 35 ms
22,432 KB |
testcase_25 | AC | 59 ms
21,904 KB |
testcase_26 | AC | 59 ms
21,880 KB |
testcase_27 | AC | 36 ms
21,784 KB |
testcase_28 | AC | 32 ms
22,856 KB |
testcase_29 | AC | 58 ms
22,692 KB |
testcase_30 | AC | 99 ms
21,892 KB |
testcase_31 | AC | 20 ms
22,612 KB |
ソースコード
#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){ visited[i][j] = true; 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; }