結果

問題 No.1704 Many Bus Stops (easy)
ユーザー puznekopuzneko
提出日時 2021-10-30 00:22:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,029 ms / 2,000 ms
コード長 881 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 82,664 KB
実行使用メモリ 78,208 KB
最終ジャッジ日時 2024-04-16 16:03:41
合計ジャッジ時間 31,741 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
61,440 KB
testcase_01 AC 1,001 ms
77,696 KB
testcase_02 AC 404 ms
77,568 KB
testcase_03 AC 398 ms
77,696 KB
testcase_04 AC 406 ms
77,440 KB
testcase_05 AC 399 ms
77,440 KB
testcase_06 AC 397 ms
77,440 KB
testcase_07 AC 411 ms
77,568 KB
testcase_08 AC 399 ms
77,804 KB
testcase_09 AC 396 ms
77,784 KB
testcase_10 AC 403 ms
77,568 KB
testcase_11 AC 402 ms
77,276 KB
testcase_12 AC 403 ms
77,568 KB
testcase_13 AC 404 ms
77,824 KB
testcase_14 AC 400 ms
77,568 KB
testcase_15 AC 409 ms
78,176 KB
testcase_16 AC 400 ms
77,600 KB
testcase_17 AC 405 ms
77,524 KB
testcase_18 AC 400 ms
77,636 KB
testcase_19 AC 402 ms
77,440 KB
testcase_20 AC 396 ms
77,184 KB
testcase_21 AC 402 ms
77,208 KB
testcase_22 AC 1,001 ms
77,952 KB
testcase_23 AC 1,029 ms
77,656 KB
testcase_24 AC 1,006 ms
77,568 KB
testcase_25 AC 1,006 ms
77,952 KB
testcase_26 AC 1,014 ms
77,824 KB
testcase_27 AC 1,012 ms
77,696 KB
testcase_28 AC 1,012 ms
78,208 KB
testcase_29 AC 1,019 ms
77,696 KB
testcase_30 AC 1,007 ms
77,920 KB
testcase_31 AC 1,017 ms
77,952 KB
testcase_32 AC 1,008 ms
78,080 KB
testcase_33 AC 1,003 ms
78,080 KB
testcase_34 AC 998 ms
78,040 KB
testcase_35 AC 1,014 ms
77,440 KB
testcase_36 AC 1,011 ms
77,656 KB
testcase_37 AC 985 ms
77,824 KB
testcase_38 AC 1,008 ms
77,936 KB
testcase_39 AC 1,004 ms
77,696 KB
testcase_40 AC 1,007 ms
77,848 KB
testcase_41 AC 999 ms
77,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin

def matdot(a,b,mod):
    matsize = len(a)
    val = [[0 for i in range(matsize)] for j in range(matsize)]
    for i in range(matsize):
        for j in range(matsize):
            for k in range(matsize):
                val[i][j] = (val[i][j] + a[i][k] * b[k][j]) % mod
    return val

def powmodmat(n,pow,mod):
    matsize = len(n)
    val = [[0 for i in range(matsize)] for j in range(matsize)]
    for i in range(matsize):
        val[i][i] = 1
    while pow > 0:
        if pow & 1:
            val = matdot(val, n, mod)
        pow = pow >> 1
        n = matdot(n, n, mod)
    return val

t, *a = map(int, stdin.read().split())
p = 10**9+7
inv3 = (p+1) // 3
mat = [[inv3,0,0,0,inv3,inv3],[0,inv3,0,inv3,0,inv3],[0,0,inv3,inv3,inv3,0],[1,0,0,0,0,0],[0,1,0,0,0,0],[0,0,1,0,0,0]]

for i in range(t):
    kari = powmodmat(mat,a[i],p)
    print(kari[0][0])
0