結果

問題 No.4 おもりと天秤
ユーザー ducktailducktail
提出日時 2017-09-12 15:38:50
言語 OCaml
(5.1.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 565 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 21,448 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-17 08:43:51
合計ジャッジ時間 1,106 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 12 ms
11,392 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 12 ms
11,392 KB
testcase_08 AC 10 ms
11,264 KB
testcase_09 AC 10 ms
11,264 KB
testcase_10 AC 11 ms
11,392 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 12 ms
11,392 KB
testcase_19 AC 11 ms
11,392 KB
testcase_20 AC 11 ms
11,520 KB
testcase_21 AC 11 ms
11,264 KB
testcase_22 AC 12 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

open Printf
open Scanf

let () =
  let mx = 10001 in
  let n = scanf "%d " (fun x -> x) in
  let ws = Array.init n (fun _ -> let w = scanf "%d " (fun x -> x) in w) in
  let dp = Array.make_matrix (n+1) mx false in
  let rec loop i j =
    if i = n then ()
    else if j = mx then loop (i+1) 0
    else if dp.(i).(j) then begin
        dp.(i+1).(j+ws.(i)) <- true;
        dp.(i+1).(abs (j - ws.(i))) <- true;
        loop i (j+1)
      end
    else loop i (j+1) in
  dp.(0).(0) <- true;
  loop 0 0;
  printf "%s\n" (if dp.(n).(0) then "possible" else "impossible")
0