結果

問題 No.1588 Connection
ユーザー tnakao0123tnakao0123
提出日時 2021-07-11 12:45:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,600 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 96,624 KB
実行使用メモリ 24,432 KB
平均クエリ数 551.41
最終ジャッジ日時 2023-09-24 12:04:28
合計ジャッジ時間 4,167 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,424 KB
testcase_01 AC 26 ms
23,868 KB
testcase_02 AC 27 ms
23,568 KB
testcase_03 AC 27 ms
24,420 KB
testcase_04 AC 27 ms
24,432 KB
testcase_05 AC 27 ms
23,412 KB
testcase_06 AC 25 ms
23,400 KB
testcase_07 AC 24 ms
23,664 KB
testcase_08 AC 26 ms
23,400 KB
testcase_09 AC 27 ms
23,664 KB
testcase_10 AC 27 ms
23,436 KB
testcase_11 AC 27 ms
23,544 KB
testcase_12 AC 58 ms
23,412 KB
testcase_13 AC 63 ms
23,556 KB
testcase_14 AC 28 ms
24,372 KB
testcase_15 AC 25 ms
23,664 KB
testcase_16 AC 24 ms
23,448 KB
testcase_17 AC 25 ms
24,012 KB
testcase_18 AC 24 ms
24,384 KB
testcase_19 AC 24 ms
23,400 KB
testcase_20 AC 26 ms
24,384 KB
testcase_21 AC 107 ms
23,664 KB
testcase_22 AC 104 ms
24,420 KB
testcase_23 AC 59 ms
24,060 KB
testcase_24 AC 46 ms
23,400 KB
testcase_25 AC 69 ms
24,060 KB
testcase_26 AC 67 ms
24,420 KB
testcase_27 AC 45 ms
23,412 KB
testcase_28 AC 36 ms
23,688 KB
testcase_29 AC 99 ms
23,688 KB
testcase_30 AC 101 ms
23,388 KB
testcase_31 AC 23 ms
23,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1588.cc:  No.1588 Connection - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500;
const int dxs[] = { 1, 0, -1, 0 }, dys[] = { 0, -1, 0, 1 };
enum { W = 0, B = 1 };

/* typedef */

typedef pair<int,int> pii;
typedef queue<pii> qpii;

/* global variables */

int ds[MAX_N][MAX_N];

/* subroutines */

int check(int y, int x, int n) {
  if (y == n - 1 && x == n - 1) ds[y][x] = B;
  if (ds[y][x] >= 0) return ds[y][x];

  printf("%d %d\n", y + 1, x + 1); fflush(stdout);

  char s[8];
  scanf("%s", s);
  if (s[0] == 'W') return (ds[y][x] = W);
  if (s[0] == 'B') return (ds[y][x] = B);
  return -1;
}

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  memset(ds, -1, sizeof(ds));
  ds[0][0] = B;

  qpii q;
  q.push(pii(0, 0));

  while (! q.empty()) {
    pii u = q.front(); q.pop();
    int uy = u.first, ux = u.second;
    if (uy == n - 1 && ux == n - 1) {
      puts("Yes"); fflush(stdout);
      return 0;
    }

    for (int di = 0; di < 4; di++) {
      int vy = uy + dys[di], vx = ux + dxs[di];
      if (vy >= 0 && vy < n && vx >= 0 && vx < n && ds[vy][vx] < 0) {
	int f = check(vy, vx, n);
	if (f < 0) return 0;

	if (f == B) q.push(pii(vy, vx));
      }
    }
  }

  puts("No"); fflush(stdout);
  return 0;
}
0