結果

問題 No.1588 Connection
ユーザー Daniel MurphyDaniel Murphy
提出日時 2021-07-08 23:23:27
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 1,770 ms
使用メモリ 22,692 KB
平均クエリ数 551.84
最終ジャッジ日時 2023-02-15 01:12:17
合計ジャッジ時間 4,816 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 19 ms
22,360 KB
testcase_01 AC 18 ms
22,540 KB
testcase_02 AC 19 ms
22,252 KB
testcase_03 AC 19 ms
21,992 KB
testcase_04 AC 21 ms
21,756 KB
testcase_05 AC 20 ms
21,916 KB
testcase_06 AC 20 ms
21,880 KB
testcase_07 AC 19 ms
21,940 KB
testcase_08 AC 21 ms
21,768 KB
testcase_09 AC 22 ms
22,588 KB
testcase_10 AC 22 ms
22,588 KB
testcase_11 AC 23 ms
22,432 KB
testcase_12 AC 50 ms
21,760 KB
testcase_13 AC 56 ms
21,928 KB
testcase_14 AC 20 ms
22,692 KB
testcase_15 AC 19 ms
21,880 KB
testcase_16 AC 19 ms
22,588 KB
testcase_17 AC 21 ms
21,796 KB
testcase_18 AC 19 ms
22,432 KB
testcase_19 AC 19 ms
21,928 KB
testcase_20 AC 20 ms
21,880 KB
testcase_21 AC 94 ms
22,444 KB
testcase_22 AC 94 ms
21,756 KB
testcase_23 AC 50 ms
22,252 KB
testcase_24 AC 35 ms
21,980 KB
testcase_25 AC 58 ms
22,692 KB
testcase_26 AC 56 ms
22,576 KB
testcase_27 AC 35 ms
21,744 KB
testcase_28 AC 30 ms
22,264 KB
testcase_29 AC 95 ms
22,420 KB
testcase_30 AC 94 ms
22,576 KB
testcase_31 AC 19 ms
22,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0