結果
| 問題 |
No.1588 Connection
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2023-04-19 00:37:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 115 ms / 2,000 ms |
| コード長 | 1,356 bytes |
| コンパイル時間 | 1,048 ms |
| コンパイル使用メモリ | 115,540 KB |
| 最終ジャッジ日時 | 2025-02-12 10:05:00 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 31 |
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>
using namespace std;
int main(){
int H, W, h, w, nh, nw, x;
cin >> H >> x;
string res;
W = H;
queue<pair<int, int>> que;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<vector<int>> dist(H, vector<int>(W, -1));
vector<vector<int>> field(H, vector<int>(W));
dist[0][0] = 0;
que.push({0, 0});
while(!que.empty()){
tie(h, w) = que.front();
if (h == H-1 && w == W-1){
cout << "Yes" << endl;
return 0;
}
que.pop();
for (int dir=0; dir < 4; dir++){
nh = h + dx[dir];
nw = w + dy[dir];
if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
if (dist[nh][nw] != -1) continue;
if (field[nh][nw] == -1) continue;
cout << nh+1 << " " << nw+1 << endl;
cin >> res;
if (res == "-1") exit(0);
else if (res == "Black"){
dist[nh][nw] = dist[h][w] + 1;
que.push({nh, nw});
}
else field[nh][nw] = -1;
}
}
cout << "No" << endl;
return 0;
}
srjywrdnprkt