結果

問題 No.1588 Connection
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-07-12 17:39:16
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 966 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 95,484 KB
平均クエリ数 273.12
最終ジャッジ日時 2023-09-24 12:07:59
合計ジャッジ時間 7,265 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
87,464 KB
testcase_01 WA -
testcase_02 AC 108 ms
87,032 KB
testcase_03 AC 109 ms
87,720 KB
testcase_04 AC 109 ms
87,408 KB
testcase_05 AC 113 ms
87,288 KB
testcase_06 AC 109 ms
87,332 KB
testcase_07 AC 110 ms
87,244 KB
testcase_08 AC 110 ms
87,524 KB
testcase_09 AC 111 ms
87,928 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 121 ms
86,992 KB
testcase_14 AC 115 ms
87,876 KB
testcase_15 AC 114 ms
87,608 KB
testcase_16 AC 111 ms
87,808 KB
testcase_17 AC 114 ms
87,360 KB
testcase_18 AC 115 ms
87,452 KB
testcase_19 AC 110 ms
87,844 KB
testcase_20 AC 120 ms
88,848 KB
testcase_21 AC 213 ms
94,300 KB
testcase_22 AC 210 ms
94,520 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 175 ms
94,436 KB
testcase_26 AC 172 ms
94,332 KB
testcase_27 AC 135 ms
92,484 KB
testcase_28 AC 122 ms
87,248 KB
testcase_29 AC 262 ms
95,484 KB
testcase_30 AC 205 ms
93,244 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n, m = map(int, input().split())
if n ** 2 - (2 * n - 1) < m: exit(print("No"))
sx, sy = 0, 0
gx, gy = n - 1, n - 1
INF = 10 ** 18

def bfs():
    d = [[-1] * n for i in range(n)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
 
    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0
 
    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            exit(print("Yes"))
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if nx == n - 1 and ny == n - 1: exit(print("Yes"))
            if 0 <= nx < n and 0 <= ny < n and d[nx][ny] == -1:
                print(nx + 1, ny + 1)
                res = input()
                if res == "Black":
                    que.append((nx, ny))
                    d[nx][ny] = 0
                    break
                else:
                    d[nx][ny] = 1
    return d[gy][gx]

print("Yes" if bfs() == 0 else "No")
0