結果

問題 No.4 おもりと天秤
ユーザー MiyamonYMiyamonY
提出日時 2019-09-05 11:41:16
言語 Scheme
(Gauche-0.9.14)
結果
WA  
実行時間 -
コード長 607 bytes
コンパイル時間 50 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 17,488 KB
最終ジャッジ日時 2023-09-01 03:00:24
合計ジャッジ時間 4,624 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
12,872 KB
testcase_01 AC 25 ms
12,664 KB
testcase_02 AC 28 ms
13,020 KB
testcase_03 AC 27 ms
12,836 KB
testcase_04 AC 28 ms
13,252 KB
testcase_05 AC 180 ms
15,604 KB
testcase_06 AC 25 ms
12,744 KB
testcase_07 AC 179 ms
15,656 KB
testcase_08 AC 177 ms
15,744 KB
testcase_09 AC 168 ms
15,540 KB
testcase_10 AC 178 ms
15,592 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 25 ms
12,808 KB
testcase_14 WA -
testcase_15 AC 25 ms
12,648 KB
testcase_16 AC 26 ms
12,940 KB
testcase_17 AC 26 ms
12,732 KB
testcase_18 AC 172 ms
15,728 KB
testcase_19 AC 175 ms
17,488 KB
testcase_20 AC 178 ms
15,592 KB
testcase_21 AC 180 ms
15,728 KB
testcase_22 AC 178 ms
15,696 KB
権限があれば一括ダウンロードができます

ソースコード

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