結果
問題 | No.1588 Connection |
ユーザー | simkaren |
提出日時 | 2021-07-09 14:28:37 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 1,744 bytes |
コンパイル時間 | 2,267 ms |
コンパイル使用メモリ | 193,976 KB |
実行使用メモリ | 24,336 KB |
平均クエリ数 | 551.19 |
最終ジャッジ日時 | 2023-09-24 12:02:21 |
合計ジャッジ時間 | 5,671 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
24,156 KB |
testcase_01 | AC | 27 ms
23,280 KB |
testcase_02 | AC | 26 ms
23,208 KB |
testcase_03 | AC | 26 ms
24,168 KB |
testcase_04 | AC | 26 ms
23,568 KB |
testcase_05 | AC | 27 ms
23,664 KB |
testcase_06 | AC | 27 ms
23,868 KB |
testcase_07 | AC | 26 ms
23,664 KB |
testcase_08 | AC | 29 ms
24,108 KB |
testcase_09 | AC | 29 ms
23,364 KB |
testcase_10 | AC | 30 ms
23,880 KB |
testcase_11 | AC | 30 ms
24,336 KB |
testcase_12 | AC | 61 ms
24,156 KB |
testcase_13 | AC | 68 ms
23,460 KB |
testcase_14 | AC | 27 ms
23,364 KB |
testcase_15 | AC | 27 ms
23,952 KB |
testcase_16 | AC | 26 ms
23,652 KB |
testcase_17 | AC | 27 ms
23,256 KB |
testcase_18 | AC | 26 ms
23,868 KB |
testcase_19 | AC | 27 ms
24,156 KB |
testcase_20 | AC | 28 ms
23,676 KB |
testcase_21 | AC | 112 ms
23,856 KB |
testcase_22 | AC | 111 ms
23,256 KB |
testcase_23 | AC | 60 ms
24,312 KB |
testcase_24 | AC | 46 ms
23,424 KB |
testcase_25 | AC | 71 ms
23,652 KB |
testcase_26 | AC | 69 ms
23,496 KB |
testcase_27 | AC | 45 ms
23,568 KB |
testcase_28 | AC | 40 ms
24,012 KB |
testcase_29 | AC | 110 ms
23,196 KB |
testcase_30 | AC | 109 ms
23,460 KB |
testcase_31 | AC | 26 ms
23,412 KB |
コンパイルメッセージ
main.cpp: 関数 ‘bool bfs()’ 内: main.cpp:32:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 32 | auto [x, y] = q.front(); | ^
ソースコード
#pragma GCC optimize("Ofast", "unroll-loops") #include <bits/stdc++.h> using namespace std; int N, M; void readNM(void){ cin >> N >> M; } bool isBlack(int i, int j){ static map<pair<int, int>, int> memo; // 1: 白, 2: 黒 static int black_found = 2; if (i == 0 && j == 0) return true; if (i == N - 1 && j == N - 1) return true; int tmp = memo[{i, j}]; if (tmp > 0) return (tmp == 2); if (black_found == M) return false; cout << (i + 1) << " " << (j + 1) << endl; string res; cin >> res; assert(res != "-1"); memo[{i, j}] = res == "Black" ? 2 : 1; if (res == "Black") ++black_found; return res == "Black"; } bool bfs(void){ queue<pair<int, int>> q; vector<vector<int>> visited(N, vector<int>(N, 0)); q.emplace(0, 0); while (!q.empty()){ auto [x, y] = q.front(); q.pop(); // 上 if (x > 0 && !visited[x - 1][y] && isBlack(x - 1, y)){ visited[x - 1][y] = 1; q.emplace(x - 1, y); } // 下 if (x < N - 1 && !visited[x + 1][y] && isBlack(x + 1, y)){ if (x == N - 2 && y == N - 1) return true; visited[x + 1][y] = 1; q.emplace(x + 1, y); } // 右 if (y < N - 1 && !visited[x][y + 1] && isBlack(x, y + 1)){ if (x == N - 1 && y == N - 2) return true; visited[x][y + 1] = 1; q.emplace(x, y + 1); } // 左 if (y > 0 && !visited[x][y - 1] && isBlack(x, y - 1)){ visited[x][y - 1] = 1; q.emplace(x, y - 1); } } return false; } int main(void){ readNM(); if (bfs()) cout << "Yes" << endl; else cout << "No" << endl; return 0; }