結果
| 問題 |
No.1588 Connection
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-08 22:44:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 103 ms / 2,000 ms |
| コード長 | 1,103 bytes |
| コンパイル時間 | 1,834 ms |
| コンパイル使用メモリ | 177,272 KB |
| 実行使用メモリ | 25,220 KB |
| 平均クエリ数 | 551.19 |
| 最終ジャッジ日時 | 2024-07-17 11:39:37 |
| 合計ジャッジ時間 | 4,830 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;
typedef long long ll;
int main() {
int N, M, dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
string T;
cin >> N >> M;
vector<vector<int>> c(N, vector<int>(N, -1));
queue<pair<int, int>> q;
q.push(make_pair(0, 0));
c[0][0] = 1;
while (!q.empty()) {
auto p = q.front();
q.pop();
int x = p.first, y = p.second;
rep(i, 0, 4) {
int nx = x + dx[i], ny = y + dy[i];
if (nx == N - 1 && ny == N - 1) {
cout << "Yes" << endl;
return 0;
}
if (nx < 0 || nx >= N || ny < 0 || ny >= N) continue;
if (c[nx][ny] != -1) continue;
cout << nx + 1 << " " << ny + 1 << endl;
cin >> T;
if (T == "-1") return 0;
if (T == "Black") {
c[nx][ny] = 1;
q.push(make_pair(nx, ny));
} else {
c[nx][ny] = 0;
}
}
}
cout << "No" << endl;
}