結果
問題 |
No.44 DPなすごろく
|
ユーザー |
![]() |
提出日時 | 2017-07-29 13:18:21 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,062 bytes |
コンパイル時間 | 2,858 ms |
コンパイル使用メモリ | 65,616 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-30 01:52:57 |
合計ジャッジ時間 | 3,709 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'sequtils' [UnusedImport]
ソースコード
import strutils,sequtils var m = 1_000_000_009 type Matrix[H,W: static[int]] = array[1..H,array[1..W,int64]] proc `+`[H,W](a,b:Matrix[H,W]):Matrix[H,W] = for i in 1..high(a): for j in 1..high(a[0]): result[i][j] = a[i][j] + b[i][j] proc `*`[Ha,Wa,Wb](a:Matrix[Ha,Wa],b:Matrix[Wa,Wb]):Matrix[Ha,Wb] = var k : int64 for i in 1.. Ha: for j in 1..Wb: k = 0 for ai in 1..Wa: k = (k + a[i][ai] * b[ai][j]) # mod m result[i][j] = k proc powMatrix[W,H](a : Matrix[W,H], n : int64):Matrix[W,H] = if n == 1: return a if n mod 2 == 0: return powMatrix(a * a,n div 2) else: return powMatrix(a * a,n div 2) * a proc printMatrix(A: Matrix)= for a in A: echo a.join(", ") proc fib(n : int64): int64 = if n == 0: return 0 var A : Matrix[2,2] = [[1.int64,1.int64],[1.int64,0.int64]] return (powMatrix(A,n))[2][1] var N = stdin.readline.parseBiggestInt ans : int64 ans = fib(N + 1) echo ans