結果

問題 No.566 だいたい完全二分木
ユーザー ducktailducktail
提出日時 2018-01-01 14:31:49
言語 Scheme
(Gauche-0.9.14)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 474 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 6,812 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-06-02 05:29:26
合計ジャッジ時間 1,619 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
15,872 KB
testcase_01 AC 20 ms
15,872 KB
testcase_02 AC 20 ms
15,744 KB
testcase_03 AC 20 ms
15,872 KB
testcase_04 AC 21 ms
15,744 KB
testcase_05 AC 21 ms
15,744 KB
testcase_06 AC 21 ms
16,000 KB
testcase_07 AC 21 ms
16,128 KB
testcase_08 AC 22 ms
16,512 KB
testcase_09 AC 27 ms
17,024 KB
testcase_10 AC 29 ms
17,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

(define (cb-tree l r)
  (reverse
   (let helper ([l l]
                [r r]
                [ls '()])
     (let ([m (quotient (+ l r) 2)])
       (cond [(= l r) (cons m ls)]
             [else (helper (+ m 1) r (helper l (- m 1) (cons m ls)))])))))

(define (main args)
  (let ([k (read)])
    (print
     (let* ([cbt (cb-tree 1 (- (expt 2 k) 1))]
            [pcbt (cons (cadr cbt) (cons (car cbt) (cddr cbt)))])
       (string-join (map number->string pcbt) " "))))
  0)
0