結果

問題 No.4 おもりと天秤
ユーザー pocaristpocarist
提出日時 2015-09-01 18:57:57
言語 F#
(.NET 7)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 681 bytes
コンパイル時間 5,225 ms
コンパイル使用メモリ 165,396 KB
実行使用メモリ 25,500 KB
最終ジャッジ日時 2023-09-08 16:25:17
合計ジャッジ時間 7,486 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
22,860 KB
testcase_01 AC 79 ms
24,836 KB
testcase_02 AC 79 ms
22,776 KB
testcase_03 AC 80 ms
22,784 KB
testcase_04 AC 79 ms
22,788 KB
testcase_05 AC 84 ms
23,544 KB
testcase_06 AC 78 ms
22,828 KB
testcase_07 AC 84 ms
25,500 KB
testcase_08 AC 80 ms
22,916 KB
testcase_09 AC 88 ms
24,404 KB
testcase_10 AC 84 ms
23,456 KB
testcase_11 AC 80 ms
24,668 KB
testcase_12 AC 79 ms
22,772 KB
testcase_13 AC 79 ms
24,868 KB
testcase_14 AC 79 ms
24,712 KB
testcase_15 AC 79 ms
24,648 KB
testcase_16 AC 78 ms
20,720 KB
testcase_17 AC 79 ms
24,772 KB
testcase_18 AC 86 ms
23,412 KB
testcase_19 AC 83 ms
21,408 KB
testcase_20 AC 83 ms
23,328 KB
testcase_21 AC 82 ms
23,136 KB
testcase_22 AC 83 ms
23,200 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

(* http://yukicoder.me/problems/19 *)

open System

[<EntryPoint>]
let main argv = 
    let N = Console.ReadLine() |> int
    let W = Console.ReadLine().Split([|' '|]) |> Array.map int
    let total = Array.sum W
    let U = total / 2
    let solve () =
        if U * 2 <> total then false else
        let dp = Array2D.zeroCreate<int> (N+1) (U+1)
        for i = N-1 downto 0 do
            for u = 0 to U do
                if u < W.[i] then
                    dp.[i,u] <- dp.[i+1,u]
                else
                    dp.[i,u] <- max dp.[i+1,u] (dp.[i+1,u-W.[i]] + W.[i])
        dp.[0, U] = U
    if solve () then "possible" else "impossible"
    |> printfn "%s"
    0
0