結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー wolgnikwolgnik
提出日時 2021-05-28 22:36:23
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,013 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 77,504 KB
最終ジャッジ日時 2023-08-07 06:27:31
合計ジャッジ時間 12,629 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,192 KB
testcase_01 AC 108 ms
75,880 KB
testcase_02 AC 86 ms
76,212 KB
testcase_03 AC 71 ms
71,232 KB
testcase_04 AC 73 ms
71,304 KB
testcase_05 AC 337 ms
77,092 KB
testcase_06 AC 269 ms
76,132 KB
testcase_07 AC 402 ms
77,020 KB
testcase_08 AC 102 ms
76,164 KB
testcase_09 AC 96 ms
76,088 KB
testcase_10 AC 80 ms
75,932 KB
testcase_11 AC 646 ms
77,004 KB
testcase_12 AC 72 ms
71,068 KB
testcase_13 AC 78 ms
76,204 KB
testcase_14 AC 84 ms
76,100 KB
testcase_15 AC 709 ms
77,088 KB
testcase_16 AC 816 ms
77,244 KB
testcase_17 AC 789 ms
77,160 KB
testcase_18 AC 725 ms
77,048 KB
testcase_19 AC 727 ms
76,908 KB
testcase_20 AC 802 ms
77,248 KB
testcase_21 AC 792 ms
77,044 KB
testcase_22 AC 740 ms
77,048 KB
testcase_23 AC 643 ms
76,852 KB
testcase_24 AC 739 ms
77,504 KB
testcase_25 AC 1,013 ms
77,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N, K, L = map(int, input().split())
mod = 10 ** 9 + 7

dp = [[0] * N for _ in range(N)]

for i in range(N):
  for j in range(i + 1, i + L + 1): dp[i][j % N] += 1

def ArrayMultiple(a, b, mod):
  n = len(a)
  m = len(b[0])
  c = [[0] * n for _ in range(n)]
  for i in range(n):
    for j in range(m):
      for k in range(n):
        c[i][j] += a[i][k] * b[k][j]
        c[i][j] %= mod
  return c

def ArrayPower(a, k, mod):
  bn = list(bin(k)[2: ])
  ln = len(bn)
  n = len(a)
  bn.reverse()
  res = [[int(i == x) for i in range(n)] for x in range(n)]
  for i in range(ln):
    if int(bn[i]):
      res = ArrayMultiple(res, a, mod)
    a = ArrayMultiple(a, a, mod)
  return res

res = ArrayPower(dp, K, mod)[0]
for r in res: print(r)
0