結果

問題 No.1588 Connection
ユーザー qibqib
提出日時 2023-01-22 17:30:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 316 ms / 2,000 ms
コード長 1,075 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 99,192 KB
平均クエリ数 551.38
最終ジャッジ日時 2023-09-07 03:01:12
合計ジャッジ時間 8,945 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
87,408 KB
testcase_01 AC 120 ms
88,008 KB
testcase_02 AC 120 ms
87,648 KB
testcase_03 AC 121 ms
87,984 KB
testcase_04 AC 122 ms
87,300 KB
testcase_05 AC 120 ms
87,764 KB
testcase_06 AC 122 ms
88,028 KB
testcase_07 AC 121 ms
87,568 KB
testcase_08 AC 125 ms
87,996 KB
testcase_09 AC 126 ms
87,412 KB
testcase_10 AC 127 ms
87,700 KB
testcase_11 AC 129 ms
87,144 KB
testcase_12 AC 258 ms
94,828 KB
testcase_13 AC 225 ms
95,180 KB
testcase_14 AC 126 ms
92,584 KB
testcase_15 AC 127 ms
92,704 KB
testcase_16 AC 124 ms
92,668 KB
testcase_17 AC 124 ms
92,416 KB
testcase_18 AC 126 ms
92,752 KB
testcase_19 AC 127 ms
92,612 KB
testcase_20 AC 130 ms
92,168 KB
testcase_21 AC 315 ms
99,032 KB
testcase_22 AC 316 ms
99,192 KB
testcase_23 AC 209 ms
94,524 KB
testcase_24 AC 168 ms
93,932 KB
testcase_25 AC 244 ms
99,144 KB
testcase_26 AC 242 ms
99,112 KB
testcase_27 AC 164 ms
92,876 KB
testcase_28 AC 156 ms
92,916 KB
testcase_29 AC 302 ms
94,760 KB
testcase_30 AC 286 ms
95,084 KB
testcase_31 AC 122 ms
87,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys

n, m = map(int, input().split())
dist = [[None for _ in range(n)] for _ in range(n)]
dist[0][0] = 0
used = [[None for _ in range(n)] for _ in range(n)]
used[0][0] = False
used[-1][-1] = False

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

gx, gy = n - 1, n - 1

dq = deque()
dq.append((0, 0))
rest = 3000
while len(dq) > 0:
  cx, cy = dq.popleft()

  for i in range(4):
    nx = cx + dx[i]
    if nx < 0 or nx >= n:
      continue
    ny = cy + dy[i]
    if ny < 0 or ny >= n:
      continue
    if not dist[nx][ny] is None:
      continue
    if used[nx][ny] is None:
      if rest <= 0:
        break

      rest -= 1
      print(*[nx + 1, ny + 1], sep=" ")
      sys.stdout.flush()
      t = input()
      if t == "Black":
        used[nx][ny] = False
      elif t == "White":
        used[nx][ny] = True

    if not used[nx][ny]:
      dist[nx][ny] = dist[cx][cy] + 1
      dq.append((nx, ny))

  if not dist[gx][gy] is None:
    print("Yes")
    sys.stdout.flush()
    exit()
  elif rest <= 0:
    break

print("No")
sys.stdout.flush()
0