結果

問題 No.1105 Many Triplets
ユーザー tyawanmusityawanmusi
提出日時 2020-07-04 17:33:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 543 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 11,980 KB
実行使用メモリ 10,184 KB
最終ジャッジ日時 2023-10-19 09:22:56
合計ジャッジ時間 2,390 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,184 KB
testcase_01 AC 32 ms
10,184 KB
testcase_02 AC 29 ms
10,184 KB
testcase_03 AC 30 ms
10,184 KB
testcase_04 AC 30 ms
10,184 KB
testcase_05 AC 31 ms
10,184 KB
testcase_06 AC 30 ms
10,184 KB
testcase_07 AC 32 ms
10,184 KB
testcase_08 AC 29 ms
10,184 KB
testcase_09 AC 30 ms
10,184 KB
testcase_10 AC 31 ms
10,184 KB
testcase_11 AC 31 ms
10,184 KB
testcase_12 AC 31 ms
10,184 KB
testcase_13 AC 31 ms
10,184 KB
testcase_14 AC 31 ms
10,184 KB
testcase_15 AC 30 ms
10,184 KB
testcase_16 AC 31 ms
10,184 KB
testcase_17 AC 31 ms
10,184 KB
testcase_18 AC 31 ms
10,184 KB
testcase_19 AC 31 ms
10,184 KB
testcase_20 AC 29 ms
10,184 KB
testcase_21 AC 30 ms
10,184 KB
testcase_22 AC 29 ms
10,184 KB
testcase_23 AC 29 ms
10,184 KB
testcase_24 AC 30 ms
10,184 KB
testcase_25 AC 29 ms
10,184 KB
testcase_26 AC 29 ms
10,184 KB
testcase_27 AC 32 ms
10,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 行列a*行列b
def matprod(a,b,mod):
  n=len(a)
  l=len(b)
  m=len(b[0])
  return [[sum(a[i][k]*b[k][j]for k in range(l))%mod for j in range(m)]for i in range(n)]

# 行列a^n
def matpow(a,n,mod):
  ans=[[i==j for j in range(len(a[0]))]for i in range(len(a))]
  d=a[:][:]
  while n!=0:
    if n&1:ans=matprod(d,ans,mod)
    d=matprod(d,d,mod)
    n>>=1
  return ans

mod=10**9+7
n=int(input())
a,b,c=map(int,input().split())
ans=matprod(matpow([[1,-1,0],[0,1,-1],[-1,0,1]],n-1,mod),[[a],[b],[c]],mod)
an,bn,cn=ans
print(an[0],bn[0],cn[0])
0