結果
問題 |
No.1400 すごろくで世界旅行
|
ユーザー |
👑 ![]() |
提出日時 | 2021-02-19 22:53:52 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,160 bytes |
コンパイル時間 | 220 ms |
コンパイル使用メモリ | 82,144 KB |
実行使用メモリ | 134,400 KB |
最終ジャッジ日時 | 2024-09-16 21:34:37 |
合計ジャッジ時間 | 9,549 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 TLE * 1 -- * 7 |
ソースコード
""" 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")