結果

問題 No.1400 すごろくで世界旅行
ユーザー takelifetimetakelifetime
提出日時 2021-02-19 23:56:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 632 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 11,896 KB
実行使用メモリ 21,928 KB
最終ジャッジ日時 2023-10-17 01:15:05
合計ジャッジ時間 19,457 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,176 KB
testcase_01 AC 28 ms
10,176 KB
testcase_02 AC 28 ms
10,176 KB
testcase_03 AC 184 ms
10,428 KB
testcase_04 AC 46 ms
10,260 KB
testcase_05 AC 56 ms
10,276 KB
testcase_06 AC 773 ms
11,276 KB
testcase_07 AC 2,324 ms
12,068 KB
testcase_08 AC 216 ms
10,476 KB
testcase_09 AC 172 ms
10,400 KB
testcase_10 AC 446 ms
10,748 KB
testcase_11 AC 137 ms
10,360 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

v, d = map(int, input().split())
e = [list(map(int, list(input()))) for _ in range(v)]

def power(a, b):
    c = [[0] * v for _ in range(v)]
    for i in range(v):
        for j in range(v):
            for k in range(v):
                if a[i][k] & b[k][j]:
                    c[i][j] = 1
                    break
    return c

digits = len(bin(d)[2:])

ans = [[1 if i == j else 0 for j in range(v)] for i in range(v)]

for i in range(digits):
    if d & 1:
        ans = power(ans, e)
    e = power(e, e)
    d >>= 1

for row in ans:
    for x in row:
        if x == 0:
            print("No")
            exit()

print("Yes")
0