結果
問題 |
No.1588 Connection
|
ユーザー |
|
提出日時 | 2021-07-08 23:14:08 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 962 bytes |
コンパイル時間 | 198 ms |
コンパイル使用メモリ | 82,784 KB |
実行使用メモリ | 83,860 KB |
平均クエリ数 | 1.00 |
最終ジャッジ日時 | 2024-07-17 12:29:34 |
合計ジャッジ時間 | 4,963 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 1 |
other | RE * 31 |
ソースコード
from collections import deque N, M = map(int, input()) grid = [[None]*N for _ in range(N)] grid[0][0] = True grid[-1][-1] = True M -= 2 q = deque() q.append((0, 0)) move = [(-1, 0), (1, 0), (0, 1), (0, -1)] def ques(y, x): print(x+1, y+1) s = input() if s == 'Black': return True else: return False flag = False qs = 0 while q and M: y, x = q.popleft() for dy, dx in move: ny, nx = dy+y, dx+x if 0 <= ny < N and 0 <= nx < N and grid[nx][ny] is None: if nx == ny == N-1: flag = True q = deque() break if ques(ny, nx): grid[ny][nx] = True q.append((ny, nx)) qs += 1 if qs == 3000: q = deque() break M -= 1 else: grid[ny][nx] = False if flag: print('Yes') else: print('No')