結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
11,860 KB
testcase_01 AC 18 ms
11,688 KB
testcase_02 AC 26 ms
11,796 KB
testcase_03 AC 23 ms
11,732 KB
testcase_04 AC 26 ms
11,736 KB
testcase_05 AC 75 ms
11,628 KB
testcase_06 AC 19 ms
11,676 KB
testcase_07 AC 75 ms
11,796 KB
testcase_08 AC 19 ms
11,624 KB
testcase_09 AC 70 ms
11,944 KB
testcase_10 AC 76 ms
11,656 KB
testcase_11 AC 22 ms
11,860 KB
testcase_12 AC 19 ms
11,860 KB
testcase_13 AC 20 ms
11,728 KB
testcase_14 AC 20 ms
11,612 KB
testcase_15 AC 20 ms
11,616 KB
testcase_16 AC 22 ms
11,732 KB
testcase_17 AC 21 ms
11,864 KB
testcase_18 AC 71 ms
11,744 KB
testcase_19 AC 74 ms
11,884 KB
testcase_20 AC 75 ms
11,932 KB
testcase_21 AC 74 ms
11,740 KB
testcase_22 AC 74 ms
11,876 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 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