結果

問題 No.4 おもりと天秤
ユーザー Eliza_0xEliza_0x
提出日時 2018-05-13 12:52:30
言語 Haskell
(9.8.2)
結果
AC  
実行時間 194 ms / 5,000 ms
コード長 583 bytes
コンパイル時間 8,205 ms
コンパイル使用メモリ 162,580 KB
実行使用メモリ 93,180 KB
最終ジャッジ日時 2023-09-10 18:48:48
合計ジャッジ時間 5,554 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,204 KB
testcase_01 AC 2 ms
7,024 KB
testcase_02 AC 32 ms
23,364 KB
testcase_03 AC 13 ms
15,432 KB
testcase_04 AC 32 ms
23,332 KB
testcase_05 AC 194 ms
93,048 KB
testcase_06 AC 4 ms
9,440 KB
testcase_07 AC 184 ms
93,080 KB
testcase_08 AC 3 ms
7,352 KB
testcase_09 AC 183 ms
93,176 KB
testcase_10 AC 184 ms
93,064 KB
testcase_11 AC 12 ms
15,500 KB
testcase_12 AC 5 ms
10,292 KB
testcase_13 AC 5 ms
10,244 KB
testcase_14 AC 5 ms
10,988 KB
testcase_15 AC 5 ms
10,240 KB
testcase_16 AC 12 ms
15,132 KB
testcase_17 AC 12 ms
15,248 KB
testcase_18 AC 194 ms
93,076 KB
testcase_19 AC 182 ms
93,112 KB
testcase_20 AC 184 ms
93,056 KB
testcase_21 AC 184 ms
93,172 KB
testcase_22 AC 183 ms
93,180 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.Array
import Data.List

main = do
    n <- read <$> getLine :: IO Int
    ms <- map read . words <$> getLine :: IO [Int]
    let ns = listArray (1,n) ms :: Array Int Int
    let s = sum ms
    putStrLn $ if mod s 2 == 0 && dp ns (div s 2) 
        then "possible" else "impossible"


dp :: Array Int Int -> Int -> Bool
dp ns half = memo!(n,half)
    where
    (_,n) = bounds ns
    memo = array ((0,0), (n,10000)) [((y,x), f y x)|y<-[0..n], x<-[0..10000]]
    f 0 0 = True
    f 0 x = False
    f y x = memo!(y-1,x) || (if x-(ns!y)>=0 then memo!(y-1,x-(ns!y)) else False)
0