結果
| 問題 |
No.1588 Connection
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-08 23:23:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 118 ms / 2,000 ms |
| コード長 | 1,126 bytes |
| コンパイル時間 | 2,385 ms |
| コンパイル使用メモリ | 198,448 KB |
| 最終ジャッジ日時 | 2025-01-22 19:25:42 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 505;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
int vis[MAXN][MAXN];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
int cnt = 0;
int found = 1;
bool possible = 0;
queue<pair<int,int>> q;
q.emplace(1,1);
while (cnt < 2999 && !q.empty() && found < m) {
auto cur = q.front();
int cx = cur.first;
int cy = cur.second;
q.pop();
if (vis[cx][cy] != 0) continue;
cout << cx << " " << cy << endl;
string s; cin >> s;
if (s[0] == 'B') {
vis[cx][cy] = 1;
found++;
if ((cx == n && cy == n) || (cx == n-1 && cy == n) || (cx == n && cy == n-1)) {
possible=1;
break;
}
} else if (s[0] == 'W') {
vis[cx][cy] = 2;
continue;
} else {
cout << "ERR" << endl;
return 0;
}
cnt++;
for (int d = 0; d < 4; ++d) {
int nx = cx + dx[d];
int ny = cy + dy[d];
if (nx <= n && nx >= 1 && ny <= n && ny >= 1 && vis[nx][ny] == 0) {
q.emplace(nx, ny);
}
}
}
if (possible) {
cout << "Yes" << endl;
} else {
cout << "No\n";
}
return 0;
}