結果

問題 No.891 隣接3項間の漸化式
ユーザー MiyamonY
提出日時 2019-09-29 00:25:48
言語 Scheme
(Gauche-0.9.15)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,386 bytes
コンパイル時間 22 ms
コンパイル使用メモリ 6,692 KB
実行使用メモリ 17,792 KB
最終ジャッジ日時 2024-10-03 04:20:31
合計ジャッジ時間 2,802 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

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