結果

問題 No.40 多項式の割り算
ユーザー MiyamonY
提出日時 2019-09-06 19:02:04
言語 Scheme
(Gauche-0.9.15)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 755 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 17,920 KB
最終ジャッジ日時 2024-06-24 08:54:25
合計ジャッジ時間 2,934 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

(define (take-while-right list pred)
  (define (take-while list)
    (cond ((null? list) '())
	  ((pred (car list)) (take-while (cdr list)))
	  (else list)))
  (reverse (take-while (reverse list))))

(let* ((d (string->number (read-line)))
       (arr (list->vector (map string->number (string-split (read-line) #\space)))))

  (let loop ((i d))
    (cond ((< i 3) arr)
	  (else
	   (let1 c (vector-ref arr i)
		 (vector-set! arr i 0)
		 (vector-set! arr (- i 2) (- (vector-ref arr (- i 2)) (* -1 c))))
	   (loop (- i 1)))))

  (let1 lis (take-while-right (vector->list arr) (lambda (x) (= 0 x)))
	(cond ((= (length lis) 0) (print 0) (print 0))
	      (else
	       (print (- (length lis) 1))
	       (print (string-join (map number->string lis)" "))))))
0