結果

問題 No.2156 ぞい文字列
ユーザー k_s_y_3k_s_y_3
提出日時 2022-12-22 17:34:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 52,992 KB
最終ジャッジ日時 2024-04-29 03:46:16
合計ジャッジ時間 1,696 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,224 KB
testcase_01 AC 36 ms
51,968 KB
testcase_02 AC 42 ms
52,480 KB
testcase_03 AC 37 ms
52,096 KB
testcase_04 AC 36 ms
52,480 KB
testcase_05 AC 36 ms
52,352 KB
testcase_06 AC 35 ms
52,224 KB
testcase_07 AC 35 ms
52,992 KB
testcase_08 AC 35 ms
52,224 KB
testcase_09 AC 35 ms
52,352 KB
testcase_10 AC 36 ms
52,224 KB
testcase_11 AC 36 ms
52,608 KB
testcase_12 AC 34 ms
51,712 KB
testcase_13 AC 35 ms
51,712 KB
testcase_14 AC 34 ms
51,712 KB
testcase_15 AC 33 ms
52,096 KB
testcase_16 AC 34 ms
51,968 KB
testcase_17 AC 33 ms
51,840 KB
testcase_18 AC 33 ms
52,224 KB
testcase_19 AC 34 ms
52,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
MOD = 998244353
def mat_dot(A, B, MOD):
  #A:n*m行列, B:m*l行列
  n, m, l = len(A), len(A[0]), len(B[0])
  X = [[0]*l for i in range(n)]
  for i in range(n):
    for j in range(l):
      temp = 0
      for k in range(m):
        temp = (temp + A[i][k] * B[k][j]) % MOD
      X[i][j] = temp
  return X
 
def mat_pow(A, x, MOD):
  #A^x
  n = len(A)
  X = [[0] * n for i in range(n)]
  for i in range(n):
    X[i][i] = 1
  for i in range(x.bit_length()):
    if (x>>i)&1:
      X = mat_dot(X, A, MOD)
    A = mat_dot(A, A, MOD)
  return X

P=[[1,1],[1,0]]
X_0=[[1],[0]]

X=mat_dot(mat_pow(P,N,MOD),X_0,MOD)
print(X[0][0]-1)
0