結果

問題 No.1588 Connection
ユーザー Daniel MurphyDaniel Murphy
提出日時 2021-07-08 23:23:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 204,728 KB
実行使用メモリ 24,288 KB
平均クエリ数 551.84
最終ジャッジ日時 2023-09-24 11:38:43
合計ジャッジ時間 4,976 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
23,928 KB
testcase_01 AC 23 ms
23,544 KB
testcase_02 AC 23 ms
23,316 KB
testcase_03 AC 23 ms
24,156 KB
testcase_04 AC 23 ms
23,460 KB
testcase_05 AC 23 ms
23,352 KB
testcase_06 AC 24 ms
23,556 KB
testcase_07 AC 23 ms
23,400 KB
testcase_08 AC 25 ms
23,772 KB
testcase_09 AC 27 ms
23,472 KB
testcase_10 AC 26 ms
23,940 KB
testcase_11 AC 26 ms
23,556 KB
testcase_12 AC 55 ms
23,400 KB
testcase_13 AC 60 ms
24,048 KB
testcase_14 AC 23 ms
23,784 KB
testcase_15 AC 24 ms
24,240 KB
testcase_16 AC 23 ms
24,264 KB
testcase_17 AC 23 ms
23,436 KB
testcase_18 AC 23 ms
23,940 KB
testcase_19 AC 23 ms
23,940 KB
testcase_20 AC 24 ms
23,952 KB
testcase_21 AC 103 ms
23,352 KB
testcase_22 AC 103 ms
24,060 KB
testcase_23 AC 56 ms
23,976 KB
testcase_24 AC 41 ms
24,288 KB
testcase_25 AC 62 ms
23,916 KB
testcase_26 AC 63 ms
23,352 KB
testcase_27 AC 41 ms
23,868 KB
testcase_28 AC 35 ms
23,328 KB
testcase_29 AC 100 ms
23,436 KB
testcase_30 AC 99 ms
23,844 KB
testcase_31 AC 23 ms
23,484 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