結果

問題 No.1400 すごろくで世界旅行
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-02-19 22:53:52
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,160 bytes
コンパイル時間 1,036 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 153,200 KB
最終ジャッジ日時 2023-10-15 04:04:03
合計ジャッジ時間 10,651 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
153,200 KB
testcase_01 AC 97 ms
71,504 KB
testcase_02 AC 97 ms
71,724 KB
testcase_03 AC 213 ms
77,436 KB
testcase_04 AC 105 ms
76,912 KB
testcase_05 AC 116 ms
77,312 KB
testcase_06 AC 289 ms
77,884 KB
testcase_07 AC 479 ms
78,144 KB
testcase_08 AC 145 ms
77,344 KB
testcase_09 AC 134 ms
77,500 KB
testcase_10 AC 179 ms
77,380 KB
testcase_11 AC 126 ms
77,832 KB
testcase_12 AC 2,605 ms
78,064 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1400

行列べき乗っぽく考えて
しまいがちだが…

これは01BFSで解ける
まず、頂点を偶奇で分ける

Dの偶奇に合わせて、最短距離が基底範囲内化出せばおk

"""

import sys
from sys import stdin
from collections import deque

V,D = map(int,stdin.readline().split())

E = [ stdin.readline()[:-1] for i in range(V) ]

for s in range(V):

    q = deque([s])
    d = [float("inf")] * (2*V)
    d[s] = 0
    

    while q:
        
        nowori = q.popleft()
        v = nowori
        side = 0

        if v >= V:
            v -= V
            side = 1

        for nex in range(V):
            if E[v][nex] == "1":
                nexori = nex + V * (side^1)
                if d[nexori] > d[nowori] + 1:
                    d[nexori] = d[nowori] + 1
                    q.append(nexori)

    #print (s,d)
    if D % 2 == 0:
        for i in range(V):
            if d[i] > D:
                print ("No")
                sys.exit()
    else:
        for i in range(V,2*V):
            if d[i] > D:
                print ("No")
                sys.exit()

print ("Yes")
0