結果

問題 No.1588 Connection
ユーザー judgelawjudgelaw
提出日時 2021-07-08 23:28:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 1,117 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 27,008 KB
平均クエリ数 443.59
最終ジャッジ日時 2023-09-24 11:39:45
合計ジャッジ時間 3,888 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
24,292 KB
testcase_01 AC 39 ms
24,340 KB
testcase_02 AC 40 ms
24,584 KB
testcase_03 AC 40 ms
24,352 KB
testcase_04 AC 39 ms
24,360 KB
testcase_05 AC 38 ms
24,216 KB
testcase_06 AC 39 ms
24,568 KB
testcase_07 AC 42 ms
24,588 KB
testcase_08 AC 43 ms
24,744 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 40 ms
24,764 KB
testcase_15 AC 40 ms
24,404 KB
testcase_16 AC 38 ms
24,560 KB
testcase_17 AC 40 ms
24,368 KB
testcase_18 AC 41 ms
24,896 KB
testcase_19 AC 40 ms
24,564 KB
testcase_20 AC 50 ms
26,524 KB
testcase_21 AC 136 ms
26,680 KB
testcase_22 AC 136 ms
27,008 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 94 ms
26,420 KB
testcase_26 AC 92 ms
26,560 KB
testcase_27 AC 63 ms
24,856 KB
testcase_28 AC 74 ms
24,596 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 39 ms
24,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

##制約よりN=500,M=1000の場合最短経路でしか到達不能
##今いるマスの右と下を調べていくだけでよい

N,M=map(int,input().split())

##最短経路で移動しようとしても
##そもそも黒マスが2*N-1個以上なければ到達不能
if 2*N-1>M:
    print("No")
    exit(0)


i,j=1,1
d=[(1,0),(0,1)]

##一度見たところを配列chkに記録
chk=[[False for _ in range(N+1)]for _ in range(N+1)]
q=deque()

while M>=0:
    if i==N and j==N:
        break

    for di,dj in d:
        if i+di<=N and j+dj<=N and chk[i+di][j+dj]==False:
            print(i+di,j+dj)
            chk[i+di][j+dj]==True
            
            T=input()
            
            ##T==-1なら強制終了(str型?int型?)
            if T==-1 or T=="-1":
                exit(0)

            ##黒ならqに格納
            ##Mを-1する
            elif T=="Black":      
                M-=1
                q.appendleft((i+di,j+dj))

    if len(q):
        i,j=q.pop()
    else:
        break

if M>=0 and i==N and j==N:
    print("Yes")

else:
    print("No")
0