結果

問題 No.4 おもりと天秤
コンテスト
ユーザー _Clay____
提出日時 2018-09-18 16:10:10
言語 Scheme
(Gauche-0.9.15)
コンパイル:
true
実行:
gosh _filename_
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 796 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 160 ms
コンパイル使用メモリ 6,400 KB
実行使用メモリ 32,768 KB
最終ジャッジ日時 2026-04-01 23:55:25
合計ジャッジ時間 1,983 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

(define n (string->number (read-line)))
(define w (map string->number (string-split (read-line) " ")))
(define dp (make-vector 11000 0))
(define (check n w a)
  (unless (zero? n)
    (letrec*
      ((s (+ a (car w)))
       (check-1 (lambda (i) 
                        (unless (negative? i)
                          (begin 
                            (when (= (vector-ref dp i) 1)
                                  (vector-set! dp (+ i (car w)) 1))
                            (check-1 (- i 1)))))))
      (check-1 10000)
      (check (- n 1) (cdr w) s))))

(let1 sum (fold + 0 w)    
  (print
    (cond ((= (modulo sum 2) 1) "impossible")
          (else
            (vector-set! dp 0 1)
            (check n w 0)
            (if (zero? (vector-ref dp (/ sum 2))) "impossible" "possible")))))
0