結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2019-09-05 12:17:32 |
言語 | Scheme (Gauche-0.9.15) |
結果 |
AC
|
実行時間 | 3,497 ms / 5,000 ms |
コード長 | 803 bytes |
コンパイル時間 | 225 ms |
コンパイル使用メモリ | 5,504 KB |
実行使用メモリ | 36,992 KB |
最終ジャッジ日時 | 2025-01-03 09:01:02 |
合計ジャッジ時間 | 32,730 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
(use gauche.array) (let* ((n (string->number (read-line))) (weights (map string->number (string-split (read-line) #\space))) (total (fold + 0 weights)) (max-weight 51) (arr (make-array (shape 0 (+ n 1) 0 (+ (* max-weight n) 1)) #f))) (array-set! arr 0 0 #t) (let loop ((weights weights) (i 1)) (cond ((null? weights) (if (or (= (mod total 2) 1) (eqv? (array-ref arr n (div total 2)) #f)) (print "impossible") (print "possible"))) (else (for-each (lambda (j) (let1 pred (- j (car weights)) (if (and (>= pred 0) (array-ref arr (- i 1) pred)) (array-set! arr i j #t))) (if (array-ref arr (- i 1) j) (array-set! arr i j #t))) (iota (+ (* max-weight n) 1))) (loop (cdr weights) (+ i 1))))))