結果

問題 No.1704 Many Bus Stops (easy)
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-10-09 17:29:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 79,028 KB
最終ジャッジ日時 2023-10-11 04:07:18
合計ジャッジ時間 14,573 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
76,184 KB
testcase_01 AC 307 ms
78,376 KB
testcase_02 AC 197 ms
78,884 KB
testcase_03 AC 199 ms
78,052 KB
testcase_04 AC 199 ms
78,236 KB
testcase_05 AC 209 ms
78,524 KB
testcase_06 AC 199 ms
78,636 KB
testcase_07 AC 199 ms
78,704 KB
testcase_08 AC 211 ms
78,876 KB
testcase_09 AC 205 ms
79,028 KB
testcase_10 AC 203 ms
78,132 KB
testcase_11 AC 199 ms
78,188 KB
testcase_12 AC 202 ms
78,328 KB
testcase_13 AC 197 ms
78,584 KB
testcase_14 AC 198 ms
78,100 KB
testcase_15 AC 206 ms
78,636 KB
testcase_16 AC 198 ms
78,256 KB
testcase_17 AC 200 ms
78,116 KB
testcase_18 AC 195 ms
78,192 KB
testcase_19 AC 198 ms
78,084 KB
testcase_20 AC 197 ms
78,332 KB
testcase_21 AC 195 ms
78,812 KB
testcase_22 AC 326 ms
78,192 KB
testcase_23 AC 323 ms
78,408 KB
testcase_24 AC 320 ms
78,304 KB
testcase_25 AC 324 ms
78,364 KB
testcase_26 AC 324 ms
78,872 KB
testcase_27 AC 326 ms
78,232 KB
testcase_28 AC 330 ms
78,092 KB
testcase_29 AC 317 ms
78,620 KB
testcase_30 AC 324 ms
78,272 KB
testcase_31 AC 323 ms
78,272 KB
testcase_32 AC 316 ms
78,592 KB
testcase_33 AC 322 ms
78,088 KB
testcase_34 AC 323 ms
78,148 KB
testcase_35 AC 317 ms
78,788 KB
testcase_36 AC 326 ms
78,848 KB
testcase_37 AC 325 ms
78,316 KB
testcase_38 AC 323 ms
78,184 KB
testcase_39 AC 322 ms
78,272 KB
testcase_40 AC 316 ms
78,164 KB
testcase_41 AC 320 ms
78,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

t = int(input())
for _ in range(t):
    n = int(input())
    c,m = 3,1
    mod = 10**9+7

    cinv = pow(c,mod-2,mod)
    A = [[cinv,0,0,cinv],[0,cinv,(c-1)*cinv%mod,(c-2)*cinv%mod],[1,0,0,0],[0,1,0,0]]

    def calc(X,Y):
        ans = [[0]*4 for i in range(4)]
        for i in range(4):
            for j in range(4):
                for k in range(4):
                    ans[i][j] += X[i][k]*Y[k][j]
                    ans[i][j] %= mod
        return ans


    base = [[0]*4 for i in range(4)]
    for i in range(4):
        base[i][i] = 1

    while n:
        if n%2:
            base = calc(A,base)

        n //= 2
        A = calc(A,A)

    p = (base[2][0]*cinv+base[2][2])%mod

    ans = (1-pow(1-p,m,mod))%mod
    print(ans)
0