結果

問題 No.375 立方体のN等分 (1)
ユーザー pekempey
提出日時 2016-07-28 17:53:42
言語 Scheme
(Gauche-0.9.15)
結果
AC  
実行時間 4,385 ms / 5,000 ms
コード長 1,058 bytes
コンパイル時間 63 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 49,276 KB
最終ジャッジ日時 2024-11-06 18:12:40
合計ジャッジ時間 11,699 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

(define divisors2
  (lambda (n i res)
    (if (> (* i i) n)
      res
      (if (= (remainder n i) 0)
        (if (= (* i i) n)
          (divisors2 n (+ i 1) (cons (cons i i) res))
          (divisors2 n (+ i 1) (cons (cons i (quotient n i)) res)))
        (divisors2 n (+ i 1) res)))))

(define divisors3
  (lambda (n i res)
    (if (> (* i i i) n)
      res
      (if (= (remainder n i) 0)
        (divisors3 n (+ i 1) (append res (map (lambda (x) (cons i x)) (divisors2 (quotient n i) 1 '()))))
        (divisors3 n (+ i 1) res)))))

(define foldl
  (lambda (f e L)
    (if (null? L) e
      (foldl f (f e (car L)) (cdr L)))))

(define min-element
  (lambda (L)
    (foldl min (car L) L)))

(define solve-min
  (lambda (N)
    (min-element (map (lambda (pqr)
                        (let ((p (car pqr)) (q (cadr pqr)) (r (cddr pqr)))
                          (+ (- p 1) (- q 1) (- r 1)))) (divisors3 N 1 '())))))

(define solve-max
  (lambda (N)
    (- N 1)))

(define N (read))

(display (solve-min N))
(display " ")
(display (solve-max N))
(newline) 
0