結果

問題 No.1879 How many matchings?
ユーザー wolgnikwolgnik
提出日時 2022-03-18 22:37:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 64,468 KB
最終ジャッジ日時 2024-04-14 10:33:34
合計ジャッジ時間 1,851 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,888 KB
testcase_01 AC 46 ms
60,164 KB
testcase_02 AC 47 ms
60,804 KB
testcase_03 AC 45 ms
62,028 KB
testcase_04 AC 46 ms
61,688 KB
testcase_05 AC 46 ms
60,396 KB
testcase_06 AC 46 ms
60,472 KB
testcase_07 AC 47 ms
62,232 KB
testcase_08 AC 50 ms
61,504 KB
testcase_09 AC 52 ms
64,468 KB
testcase_10 AC 54 ms
64,304 KB
testcase_11 AC 54 ms
63,836 KB
testcase_12 AC 53 ms
64,108 KB
testcase_13 AC 53 ms
63,696 KB
testcase_14 AC 53 ms
63,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7

m = 3
move = [[0] * (1 << m) for _ in range(1 << m)]

for i in range(0, 5, 4):
  for j in range(0, 3, 2):
    for k in range(2):
      t = i + j + k

      if j: move[t][i | (k << 1) | 0] = 1
      if k and (i == 0 or j == 0): move[t][(i | (j << 1)) | 0 | 0] = 1
      if i == 0:
        move[t][4 | (k << 1) | 1] = 1
      if j == 0:
        move[t][i | (k << 1) | 1] = 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

t = ArrayPower(move, N, mod)[0]
#print(t)
res = 0
if N % 2 == 0: res = t[0]
else: res = (t[1] + t[2] + t[4]) % mod
print(res)
0