結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー convexineqconvexineq
提出日時 2021-05-28 21:57:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,056 KB
最終ジャッジ日時 2024-04-25 00:05:21
合計ジャッジ時間 4,440 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,968 KB
testcase_01 AC 50 ms
59,520 KB
testcase_02 AC 57 ms
61,312 KB
testcase_03 AC 42 ms
52,608 KB
testcase_04 AC 42 ms
52,352 KB
testcase_05 AC 111 ms
75,904 KB
testcase_06 AC 95 ms
73,088 KB
testcase_07 AC 123 ms
76,032 KB
testcase_08 AC 59 ms
63,232 KB
testcase_09 AC 56 ms
62,336 KB
testcase_10 AC 51 ms
60,032 KB
testcase_11 AC 162 ms
75,776 KB
testcase_12 AC 41 ms
51,968 KB
testcase_13 AC 50 ms
60,032 KB
testcase_14 AC 55 ms
60,416 KB
testcase_15 AC 173 ms
76,032 KB
testcase_16 AC 194 ms
76,160 KB
testcase_17 AC 190 ms
76,160 KB
testcase_18 AC 179 ms
76,160 KB
testcase_19 AC 180 ms
76,160 KB
testcase_20 AC 192 ms
76,160 KB
testcase_21 AC 190 ms
76,160 KB
testcase_22 AC 179 ms
76,160 KB
testcase_23 AC 164 ms
76,032 KB
testcase_24 AC 181 ms
75,904 KB
testcase_25 AC 229 ms
77,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def matmul(A,B): # A,B: 行列
    res = [[0]*len(B[0]) for _ in [None]*len(A)]
    for i, resi in enumerate(res):
        for k, aik in enumerate(A[i]):
            for j,bkj in enumerate(B[k]):
                resi[j] += aik*bkj
                resi[j] %= MOD
    return res

def matpow(A,p): #A^p mod M
    if p%2:
        return matmul(A, matpow(A,p-1))
    elif p > 0:
        b = matpow(A,p//2)
        return matmul(b,b)
    else:
        return [[int(i==j) for j in range(len(A))] for i in range(len(A))]


n,k,L = map(int,input().split())
MOD = 10**9+7

A = [[0]*n for _ in range(n)]
for i in range(n):
    for j in range(1,L+1):
        A[i][(i+j)%n] = 1
A = matpow(A,k)
print(*A[0],sep="\n")
0