結果

問題 No.4 おもりと天秤
ユーザー tanson
提出日時 2025-08-16 01:17:07
言語 Standard ML
(MLton 20210117)
結果
WA  
実行時間 -
コード長 1,704 bytes
コンパイル時間 3,174 ms
コンパイル使用メモリ 687,864 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-08-16 01:17:12
合計ジャッジ時間 4,442 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

fun readInt () =
    valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn)


val () =
    let
        val n = readInt ()
        val ws = Array.tabulate (n, fn _ => readInt ())
        val sum = Array.foldl (fn (w, acc) => w + acc) 0 ws
        val dp = Array.array (n + 1, Array.array ((n + 1) * 100, false))

        fun doDp () =
            (Array.update (Array.sub (dp, 0), 0, true);
             Array.appi (fn (index, w) =>
                            let
                                val i = ref 0
                            in
                                if index < n
                                then
                                    (
                                      while !i < n * 100 do
                                                        (if Array.sub (Array.sub (dp, index), !i) = true
                                                         then
                                                             (Array.update (Array.sub (dp, index + 1), !i + w, true);
                                                              Array.update (Array.sub (dp, index + 1), !i, true))
                                                         else ignore ();
                                                         i := !i + 1)
                                    )
                                else ignore ()
                            end
                        )
                        ws)
    in
        if sum mod 2 <> 0 then print "impossible\n"
        else
            (
              doDp ();
              if Array.sub (Array.sub (dp, n), sum div 2) = true then print "possible\n"
              else print "impossible\n"
            )
    end

0