結果

問題 No.1258 コインゲーム
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-10-16 21:47:26
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,503 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 94,076 KB
最終ジャッジ日時 2023-09-28 02:45:24
合計ジャッジ時間 8,844 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 492 ms
81,504 KB
testcase_01 AC 531 ms
82,232 KB
testcase_02 AC 293 ms
79,564 KB
testcase_03 AC 1,464 ms
90,496 KB
testcase_04 AC 1,753 ms
92,696 KB
testcase_05 AC 404 ms
81,516 KB
testcase_06 AC 1,332 ms
88,340 KB
testcase_07 AC 248 ms
79,512 KB
testcase_08 AC 222 ms
79,476 KB
testcase_09 AC 664 ms
83,552 KB
testcase_10 AC 1,376 ms
90,348 KB
testcase_11 AC 1,712 ms
93,080 KB
testcase_12 AC 1,151 ms
89,572 KB
testcase_13 AC 450 ms
81,568 KB
testcase_14 AC 264 ms
79,528 KB
testcase_15 AC 1,384 ms
90,368 KB
testcase_16 AC 409 ms
81,784 KB
testcase_17 AC 1,549 ms
93,168 KB
testcase_18 AC 718 ms
83,220 KB
testcase_19 AC 661 ms
82,984 KB
testcase_20 AC 1,319 ms
88,576 KB
testcase_21 AC 1,610 ms
91,264 KB
testcase_22 AC 1,134 ms
88,664 KB
testcase_23 AC 921 ms
84,828 KB
testcase_24 AC 427 ms
81,560 KB
testcase_25 AC 862 ms
85,236 KB
testcase_26 AC 703 ms
85,104 KB
testcase_27 AC 1,621 ms
90,772 KB
testcase_28 AC 535 ms
81,928 KB
testcase_29 AC 498 ms
81,356 KB
testcase_30 TLE -
testcase_31 AC 583 ms
82,484 KB
testcase_32 AC 310 ms
80,084 KB
testcase_33 AC 1,337 ms
89,384 KB
testcase_34 AC 1,471 ms
91,748 KB
testcase_35 AC 645 ms
82,892 KB
testcase_36 AC 1,469 ms
91,900 KB
testcase_37 AC 675 ms
83,768 KB
testcase_38 AC 1,500 ms
90,616 KB
testcase_39 AC 496 ms
81,820 KB
testcase_40 AC 1,777 ms
93,228 KB
testcase_41 AC 1,820 ms
93,272 KB
testcase_42 AC 1,807 ms
93,272 KB
testcase_43 AC 1,783 ms
93,472 KB
testcase_44 AC 1,769 ms
93,372 KB
testcase_45 AC 1,801 ms
93,276 KB
testcase_46 AC 1,795 ms
93,620 KB
testcase_47 AC 1,841 ms
93,352 KB
testcase_48 AC 1,811 ms
93,280 KB
testcase_49 AC 1,777 ms
93,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

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

行列累乗では?
dp[i][x] = i番目までのコインを投げて、表がx(mod2で)回出たときのスコア

表が出たとき
dp[i+1][x^1] += dp[i][x] * M
裏が出たとき
dp[i+1][x] += dp[i][x]

"""

import sys
from sys import stdin
mod = 10**9+7

#行列A,Bの積(不可能だとエラー,modに0以下の値を指定するとmodを取らなくなる)
def matrix_mul(A,B,mod):
 
    ans = [ [0] * len(B[0]) for i in range(len(A)) ]
 
    for ai in range(len(A)):
 
        for bj in range(len(B[0])):
 
            now = 0
            for same in range(len(A[0])):
                now += A[ai][same] * B[same][bj]

            if mod > 0:
                ans[ai][bj] = now % mod
            else:
                ans[ai][bj] = now
 
    return ans
 
#行列Aのx乗(当然正方行列じゃないとだめ)
def matrix_pow(A,x,mod):
 
    B = [[A[i][j] for j in range(len(A[0]))] for i in range(len(A))]
    ans = [[0] * len(A[0]) for i in range(len(A))]
    for i in range(len(A)):
        ans[i][i] = 1
 
    while x > 0:
        if x % 2 == 1:
            ans = matrix_mul(ans,B,mod)
        B = matrix_mul(B,B,mod)
 
        x//=2
    return ans

S = int(stdin.readline())
pl = []
for loop in range(S):

    N,M,X = map(int,stdin.readline().split())

    A = [ [1,0] ]
    H = [
         [1,M],
         [M,1]
        ]

    ans = matrix_mul(A , matrix_pow(H,N,mod) , mod)
    pl.append(ans[0][X] % mod)

print ("\n".join(map(str,pl)))
    
0