結果
| 問題 |
No.1588 Connection
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2021-07-09 00:10:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
QLE
(最初)
|
| 実行時間 | - |
| コード長 | 1,438 bytes |
| コンパイル時間 | 2,255 ms |
| コンパイル使用メモリ | 198,784 KB |
| 最終ジャッジ日時 | 2025-01-22 19:50:27 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 25 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int a[502][502];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= n + 1; j++) {
a[i][j] = -1;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
a[i][j] = 0;
}
}
a[1][1] = 1;
a[n][n] = 1;
m -= 2;
queue<pair<int, int>> q;
q.push({ 1, 1 });
int l = 0;
while (!q.empty() && m > 0) {
auto p = q.back(); q.pop();
pair<int, int> d[4] = { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } };
for (int k = 0; k < 4; k++) {
auto t = p;
t.first += d[k].first;
t.second += d[k].second;
int &x = a[t.first][t.second];
if (x != 0) continue;
if (l == 3000) break;
cout << t.first << ' ' << t.second << endl;
l++;
string s;
cin >> s;
if (s[0] == '-') {
exit(0);
}
x = s[0] == 'B' ? 1 : 2;
if (x == 1) {
if ((t.first == n - 1 && t.second == n) || (t.first == n && t.second == n - 1)) {
cout << "Yes" << endl;
exit(0);
}
q.push(t);
m--;
}
}
}
cout << "No" << endl;
return 0;
}
merom686