結果

問題 No.4 おもりと天秤
ユーザー MiyamonYMiyamonY
提出日時 2019-09-05 12:17:32
言語 Scheme
(Gauche-0.9.14)
結果
AC  
実行時間 3,366 ms / 5,000 ms
コード長 803 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 5,300 KB
実行使用メモリ 28,496 KB
最終ジャッジ日時 2023-09-01 22:13:56
合計ジャッジ時間 31,958 ms
ジャッジサーバーID
(参考情報)
judge11 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
18,252 KB
testcase_01 AC 65 ms
18,572 KB
testcase_02 AC 123 ms
20,268 KB
testcase_03 AC 89 ms
20,060 KB
testcase_04 AC 121 ms
20,932 KB
testcase_05 AC 3,226 ms
28,424 KB
testcase_06 AC 60 ms
18,076 KB
testcase_07 AC 3,315 ms
28,360 KB
testcase_08 AC 2,087 ms
28,336 KB
testcase_09 AC 2,100 ms
28,356 KB
testcase_10 AC 3,366 ms
28,428 KB
testcase_11 AC 69 ms
19,112 KB
testcase_12 AC 61 ms
18,136 KB
testcase_13 AC 60 ms
18,128 KB
testcase_14 AC 62 ms
18,312 KB
testcase_15 AC 62 ms
18,156 KB
testcase_16 AC 73 ms
19,508 KB
testcase_17 AC 69 ms
21,136 KB
testcase_18 AC 2,678 ms
28,416 KB
testcase_19 AC 3,162 ms
28,496 KB
testcase_20 AC 3,162 ms
28,348 KB
testcase_21 AC 3,104 ms
28,364 KB
testcase_22 AC 3,194 ms
28,400 KB
権限があれば一括ダウンロードができます

ソースコード

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 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))))))
0