結果

問題 No.4 おもりと天秤
ユーザー _Clay_____Clay____
提出日時 2018-09-18 16:18:44
言語 Scheme
(Gauche-0.9.14)
結果
AC  
実行時間 78 ms / 5,000 ms
コード長 764 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 11,920 KB
最終ジャッジ日時 2023-09-25 09:49:26
合計ジャッジ時間 2,274 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
11,856 KB
testcase_01 AC 19 ms
11,736 KB
testcase_02 AC 26 ms
11,648 KB
testcase_03 AC 24 ms
11,712 KB
testcase_04 AC 27 ms
11,756 KB
testcase_05 AC 76 ms
11,884 KB
testcase_06 AC 20 ms
11,764 KB
testcase_07 AC 78 ms
11,884 KB
testcase_08 AC 19 ms
11,780 KB
testcase_09 AC 71 ms
11,780 KB
testcase_10 AC 76 ms
11,900 KB
testcase_11 AC 23 ms
11,920 KB
testcase_12 AC 20 ms
11,756 KB
testcase_13 AC 20 ms
11,676 KB
testcase_14 AC 20 ms
11,668 KB
testcase_15 AC 20 ms
11,736 KB
testcase_16 AC 23 ms
11,740 KB
testcase_17 AC 22 ms
11,744 KB
testcase_18 AC 74 ms
11,684 KB
testcase_19 AC 75 ms
11,756 KB
testcase_20 AC 74 ms
11,884 KB
testcase_21 AC 76 ms
11,884 KB
testcase_22 AC 75 ms
11,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

(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)
  (unless (zero? n)
    (letrec
      ((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)))))

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