結果

問題 No.4 おもりと天秤
ユーザー MiyamonY
提出日時 2019-09-05 11:41:16
言語 Scheme
(Gauche-0.9.15)
結果
WA  
実行時間 -
コード長 607 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 21,120 KB
最終ジャッジ日時 2025-01-03 05:26:24
合計ジャッジ時間 3,810 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

(let* ((n (string->number (read-line)))
       (arr (map string->number (string-split (read-line) #\space))))
  (define vec (make-vector (* 100 n) #f))
  (define total (fold + 0 arr))

  (vector-set! vec 0 #t)

  (let loop ((weights arr))
    (cond ((null? weights)
	   (if (or (= (mod total 2) 1) (eqv? (vector-ref vec (div total 2)) #f))
	       (print "impossible")
	       (print "possible")))
	  (else
	   (for-each
	    (lambda (j)
	      (let1 pred (- j (car weights))
		    (if (and (>= pred 0) (vector-ref vec pred))
			(vector-set! vec j #t))))
	    (iota (* 100 n)))
	   (loop (cdr weights))))))
0