結果

問題 No.1588 Connection
ユーザー tcltktcltk
提出日時 2021-11-19 23:30:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 431 ms / 2,000 ms
コード長 1,655 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 103,008 KB
平均クエリ数 381.62
最終ジャッジ日時 2023-08-30 10:50:56
合計ジャッジ時間 13,334 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 248 ms
96,488 KB
testcase_01 AC 232 ms
96,568 KB
testcase_02 AC 231 ms
96,704 KB
testcase_03 AC 234 ms
96,524 KB
testcase_04 AC 235 ms
96,252 KB
testcase_05 AC 233 ms
96,756 KB
testcase_06 AC 233 ms
96,264 KB
testcase_07 AC 233 ms
96,604 KB
testcase_08 AC 242 ms
96,348 KB
testcase_09 AC 239 ms
96,520 KB
testcase_10 AC 240 ms
96,452 KB
testcase_11 AC 235 ms
96,112 KB
testcase_12 AC 239 ms
96,344 KB
testcase_13 AC 240 ms
96,980 KB
testcase_14 AC 237 ms
96,376 KB
testcase_15 AC 242 ms
96,784 KB
testcase_16 AC 240 ms
96,488 KB
testcase_17 AC 239 ms
96,476 KB
testcase_18 AC 236 ms
96,504 KB
testcase_19 AC 231 ms
96,844 KB
testcase_20 AC 240 ms
99,888 KB
testcase_21 AC 380 ms
102,928 KB
testcase_22 AC 379 ms
102,180 KB
testcase_23 AC 300 ms
100,472 KB
testcase_24 AC 265 ms
99,052 KB
testcase_25 AC 360 ms
102,420 KB
testcase_26 AC 361 ms
103,008 KB
testcase_27 AC 279 ms
100,204 KB
testcase_28 AC 264 ms
99,636 KB
testcase_29 AC 420 ms
100,900 KB
testcase_30 AC 431 ms
101,788 KB
testcase_31 AC 230 ms
96,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """# paste here...
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

# MAP = ['#.', '.#']

def input_wrapper(i, j):
    global query_count, black_count

    if Map[i][j] != -1:
        return Map[i][j]
    
    if query_count == 3000:
        return 0
    query_count += 1

    if black_count == M:
        return 0

    print(i+1, j+1)
    sys.stdout.flush()
    v = input()
    # if MAP[i][j] == '#':
    #     v = 'Black'
    # else:
    #     v = 'White'

    if v == 'Black':
        black_count += 1
        Map[i][j] = 1
        return 1
    elif v == 'White':
        Map[i][j] = 0
        return 0
    else:
        sys.exit()

def solve(N, M):
    hq = []
    heapq.heappush(hq, ((N-1-1)+(N-1), 1, 0))
    heapq.heappush(hq, ((N-1)+(N-1-1), 0, 1))
    while hq:
        d, i, j = heapq.heappop(hq)
        v = input_wrapper(i, j)
        if v == 1:
            for i1, j1 in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
                if (i1, j1) == (N-1, N-1):
                    return'Yes'
                if not (0 <= i1 < N and 0 <= j1 < N and Map[i1][j1] == -1):
                    continue
                d1 = (N-1-i1) + (N-1-j1)
                heapq.heappush(hq, (d1, i1, j1))
    return 'No'        


N, M = map(int, input().split())
Map = [[-1] * N for _ in range(N)]
Map[0][0] = 1
Map[N-1][N-1] = 1
query_count = 0
black_count = 0
print(solve(N, M))
sys.stdout.flush()
0