結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー wolgnikwolgnik
提出日時 2021-05-28 22:36:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,025 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2024-04-25 00:35:20
合計ジャッジ時間 11,839 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
51,968 KB
testcase_01 AC 52 ms
60,544 KB
testcase_02 AC 55 ms
61,568 KB
testcase_03 AC 41 ms
51,968 KB
testcase_04 AC 44 ms
52,352 KB
testcase_05 AC 317 ms
76,288 KB
testcase_06 AC 251 ms
72,320 KB
testcase_07 AC 391 ms
76,416 KB
testcase_08 AC 79 ms
63,360 KB
testcase_09 AC 72 ms
62,720 KB
testcase_10 AC 54 ms
60,672 KB
testcase_11 AC 650 ms
76,288 KB
testcase_12 AC 44 ms
52,224 KB
testcase_13 AC 53 ms
60,416 KB
testcase_14 AC 56 ms
61,056 KB
testcase_15 AC 716 ms
76,160 KB
testcase_16 AC 821 ms
76,416 KB
testcase_17 AC 781 ms
76,288 KB
testcase_18 AC 723 ms
76,800 KB
testcase_19 AC 725 ms
76,288 KB
testcase_20 AC 789 ms
76,672 KB
testcase_21 AC 795 ms
76,288 KB
testcase_22 AC 741 ms
76,288 KB
testcase_23 AC 644 ms
76,288 KB
testcase_24 AC 741 ms
76,800 KB
testcase_25 AC 1,025 ms
76,544 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