結果
問題 | No.1588 Connection |
ユーザー |
![]() |
提出日時 | 2021-07-09 00:49:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 100 ms / 2,000 ms |
コード長 | 1,236 bytes |
コンパイル時間 | 2,058 ms |
コンパイル使用メモリ | 200,276 KB |
最終ジャッジ日時 | 2025-01-22 19:56:18 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 31 |
ソースコード
#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; queue<pair<int, int>> q; q.push({ 1, 1 }); while (!q.empty()) { auto p = q.front(); q.pop(); pair<int, int> d[4] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } }; for (int k = 0; k < 4; k++) { auto t = p; t.first += d[k].first; t.second += d[k].second; if (t.first == n && t.second == n) { cout << "Yes" << endl; exit(0); } int x = a[t.first][t.second]; if (x != 0) continue; cout << t.first << ' ' << t.second << endl; string s; cin >> s; a[t.first][t.second] = s[0] == 'B' ? 1 : 2; if (a[t.first][t.second] == 1) { q.push(t); } } } cout << "No" << endl; return 0; }