結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2015-03-09 09:32:48 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 468 ms / 5,000 ms |
コード長 | 681 bytes |
コンパイル時間 | 3,404 ms |
コンパイル使用メモリ | 224,640 KB |
実行使用メモリ | 17,280 KB |
最終ジャッジ日時 | 2024-06-26 09:09:06 |
合計ジャッジ時間 | 6,253 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import Control.Applicative import Data.List import Data.Array solve ws = if solve' ws then "possible" else "impossible" solve' ws = go ws arr where arr = listArray ((0,0),(length ws, sum ws `div` 2 + 1)) $ True : repeat False check m = (/= []) $ filter (\((_,w),v) -> 2 * w == sum ws && v == True) $ assocs m go [] m = check m go (x:xs) m | check m = True | otherwise = let m' = accum (||) m $ filter (\((k,w),_) -> 2 * w <= sum ws) $ fmap (\((k,w),v) -> ((k+1,w+x),v)) $ filter (\(_,v) -> v == True) $ assocs m in go xs m' main = do _ <- getLine ws <- fmap (read :: String -> Int) . words <$> getLine putStrLn $ solve $ sortBy (\x y -> compare y x) $ ws