結果

問題 No.4 おもりと天秤
ユーザー MiyamonY
提出日時 2019-09-05 12:14:04
言語 Scheme
(Gauche-0.9.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 804 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 5,120 KB
実行使用メモリ 42,240 KB
最終ジャッジ日時 2025-01-03 08:50:13
合計ジャッジ時間 53,521 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

(use gauche.array)

(let* ((n (string->number (read-line)))
       (weights (map string->number (string-split (read-line) #\space)))
       (total (fold + 0 weights))
       (max-weight 100)
       (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))))))
0