結果

問題 No.891 隣接3項間の漸化式
ユーザー MiyamonYMiyamonY
提出日時 2019-09-29 00:25:48
言語 Scheme
(Gauche-0.9.14)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,386 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 7,072 KB
実行使用メモリ 17,792 KB
最終ジャッジ日時 2024-04-14 07:07:25
合計ジャッジ時間 3,799 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
17,536 KB
testcase_01 AC 47 ms
17,664 KB
testcase_02 AC 48 ms
17,664 KB
testcase_03 AC 47 ms
17,536 KB
testcase_04 AC 47 ms
17,536 KB
testcase_05 AC 48 ms
17,536 KB
testcase_06 AC 46 ms
17,536 KB
testcase_07 AC 47 ms
17,536 KB
testcase_08 AC 47 ms
17,536 KB
testcase_09 AC 48 ms
17,536 KB
testcase_10 AC 46 ms
17,664 KB
testcase_11 AC 47 ms
17,792 KB
testcase_12 AC 47 ms
17,536 KB
testcase_13 AC 30 ms
16,640 KB
testcase_14 AC 30 ms
16,640 KB
testcase_15 AC 46 ms
17,536 KB
testcase_16 AC 47 ms
17,536 KB
testcase_17 AC 29 ms
16,768 KB
testcase_18 AC 30 ms
16,640 KB
testcase_19 AC 46 ms
17,664 KB
testcase_20 AC 31 ms
16,640 KB
testcase_21 AC 30 ms
16,640 KB
testcase_22 AC 47 ms
17,536 KB
testcase_23 AC 30 ms
16,640 KB
testcase_24 AC 30 ms
16,640 KB
testcase_25 AC 46 ms
17,536 KB
testcase_26 AC 46 ms
17,536 KB
testcase_27 AC 48 ms
17,536 KB
testcase_28 AC 47 ms
17,536 KB
testcase_29 AC 47 ms
17,536 KB
testcase_30 AC 47 ms
17,536 KB
testcase_31 AC 47 ms
17,536 KB
testcase_32 AC 47 ms
17,792 KB
testcase_33 AC 47 ms
17,664 KB
testcase_34 AC 47 ms
17,792 KB
testcase_35 AC 47 ms
17,536 KB
testcase_36 AC 46 ms
17,664 KB
testcase_37 AC 47 ms
17,664 KB
testcase_38 AC 47 ms
17,664 KB
testcase_39 AC 48 ms
17,536 KB
testcase_40 AC 48 ms
17,536 KB
testcase_41 AC 49 ms
17,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

;;; File:  main.scm
;; Author: ymiyamoto
;;
;; Created on Sat Sep 28 23:46:29 2019
;;
(define-syntax read-number
  (syntax-rules ()
    ((_ nums)
     (define-values nums
       (apply values (map string->number (string-split (read-line) #\space)))))))

(define-syntax read-numbers
  (syntax-rules ()
    ((_ as)
     (define as (map string->number (string-split (read-line) #\space))))
    ((_ as n)
     (define as (map (lambda (_) (map string->number (string-split (read-line) #\space))) (iota n))))))

(define-syntax prlist
  (syntax-rules ()
    ((_ lis)
     (print (string-join (map number->string lis) " ")))))

(define-syntax 1+ (syntax-rules () ((_ x) (+ x 1))))

(define-syntax 1- (syntax-rules () ((_ x) (- x 1))))

(define MOD 1000000007)

(define (mod+ a b)
  (modulo (+ a b) MOD))

(define (mod* a b)
  (modulo (* a b) MOD))

(use util.match)

(define (matrix* x y)
  (match x
	 (((a0 b0) (c0 d0))
	  (match y
		 (((a1 b1) (c1 d1))
		  (list (list (mod+ (mod* a0 a1) (mod* b0 c1))
			      (mod+ (mod* a0 b1) (mod* b0 d1)))
			(list (mod+ (mod* c0 a1) (mod* d0 c1))
			      (mod+ (mod* c0 b1) (mod* d0 d1)))))))))

(define (solve)
  (read-number (a b n))

  (define (prod a n)
    (cond ((= n 0) '((1 0) (0 1)))
	  ((even? n) (prod (matrix* a a) (div n 2)))
	  (else
	   (matrix* a (prod a (1- n))))))

  (print (car (cadr (prod (list (list a b) '(1 0)) n)))))

(solve)
0