結果

問題 No.1588 Connection
ユーザー judgelawjudgelaw
提出日時 2021-07-08 23:36:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 1,294 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 26,760 KB
平均クエリ数 357.44
最終ジャッジ日時 2023-09-24 11:41:53
合計ジャッジ時間 4,003 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
24,432 KB
testcase_01 AC 44 ms
24,212 KB
testcase_02 AC 44 ms
24,380 KB
testcase_03 AC 43 ms
24,720 KB
testcase_04 AC 43 ms
24,932 KB
testcase_05 AC 44 ms
24,416 KB
testcase_06 AC 43 ms
24,280 KB
testcase_07 AC 44 ms
24,908 KB
testcase_08 AC 48 ms
24,792 KB
testcase_09 AC 45 ms
24,700 KB
testcase_10 AC 45 ms
24,260 KB
testcase_11 AC 45 ms
24,868 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 46 ms
24,728 KB
testcase_15 AC 46 ms
24,376 KB
testcase_16 AC 45 ms
24,796 KB
testcase_17 AC 45 ms
24,088 KB
testcase_18 AC 45 ms
24,460 KB
testcase_19 AC 47 ms
24,884 KB
testcase_20 AC 57 ms
26,760 KB
testcase_21 AC 141 ms
26,456 KB
testcase_22 AC 143 ms
26,756 KB
testcase_23 AC 82 ms
24,852 KB
testcase_24 AC 62 ms
24,304 KB
testcase_25 AC 99 ms
26,552 KB
testcase_26 AC 97 ms
26,740 KB
testcase_27 AC 64 ms
25,168 KB
testcase_28 AC 73 ms
24,452 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 43 ms
24,248 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()
cnt=3000

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

    for di,dj in d:
        if i+di==N and j+dj==N and M>=1:
            print("Yes")
            exit(0)
        elif cnt==0:
            print("No")
            exit(0)
            
        elif 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()
            cnt-=1
            ##T==-1なら強制終了(str型?int型?)
            if T==-1 or T=="-1":
                exit(0)

            ##黒ならqに格納
            ##Mを-1する
            elif T=="Black":      
                M-=1
                q.append((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